Решение должно быть AOT-совместимым.
Пример:
// npm module 1 (will not be compiled, using gulp to build npm module)
@Component({
templateUrl: './parent.component.html'
})
export class ParentComponent {}
------------------
// npm module 2 (will not be compiled, using gulp to build npm module) which has dependency npm module 1
@Component({
templateUrl: '../../node_modules/parent-module/src/parent/parent.component.html' // I need this to be replaced
})
export class ChildComponent extends ParentComponent {}
// both npm modules will be using inside a project, as dependancies and compiled at its build time.
Причина, по которой мне это нужно, заключается в том, что ParentComponent
и ChildComponent
оба разрабатываются как библиотечные проекты (Не используется какУгловые библиотечные проекты).Когда они установлены как модули npm, относительный путь неверен.
Я использовал следующие решения, но не работал при сборке aot.(Работал нормально с ng serve
)
// solution 1
const componentOptions = Object.assign(
{},
{ template: Reflect.getOwnPropertyDescriptor(ParentComponent, '__annotations__').value[0]['template'] },
{ selector: 'parent-component' }
);
@Component(componentOptions)
-----------------------
// solution 2
export function ComponentTemplate(cfg: any) {
return function (constructor: Function) {
const base = (Object.getPrototypeOf(constructor.prototype).constructor);
cfg.template = (<any>base).__annotations__[0].template;
return Component(cfg)(constructor);
};
}
@ComponentTemplate({})