export function CustomComponent(annotation: any) {
return function (target: Function) {
// call your database and get your string here
var parentTarget = Object.getPrototypeOf(target.prototype).constructor;
var parentAnnotations = Reflect.getMetadata('annotations', parentTarget);
var parentAnnotation = parentAnnotations[0];
Object.keys(parentAnnotation).forEach(key => {
if (isPresent(parentAnnotation[key])) {
if (!isPresent(annotation[key])) {
annotation[key] = parentAnnotation[key];
}
}
});
var metadata = new ComponentMetadata(annotation);
Reflect.defineMetadata('annotations', [ metadata ], target);
};
};
并使用它
@CustomComponent({
selector: 'sub'
})
export class SubComponent {
}
1 回答
有想法实现它,如果我们为组件创建自定义注释并使用它我们可以从api获取元数据,如jsp文件,并将其添加到模板而不是templateUrl
我没有创建示例代码,但粗略的想法在这里 - >
并使用它