I\'m trying to create a library of shared Angular components to use across a number of different web projects. Along with the shared component library, I\'m trying to create
You can try using special function to get annotations:
annotation.ts
declare let Reflect: any;
export function getAnnotation(typeOrFunc: Type): any[]|null {
// Prefer the direct API.
if ((typeOrFunc).annotations) {
let annotations = (typeOrFunc).annotations;
if (typeof annotations === 'function' && annotations.annotations) {
annotations = annotations.annotations;
}
return annotations[0];
}
// API of tsickle for lowering decorators to properties on the class.
if ((typeOrFunc).decorators) {
return convertTsickleDecoratorIntoMetadata((typeOrFunc).decorators)[0];
}
// API for metadata created by invoking the decorators.
if (Reflect && Reflect.getOwnMetadata) {
return Reflect.getOwnMetadata('annotations', typeOrFunc)[0];
}
return null;
}
function convertTsickleDecoratorIntoMetadata(decoratorInvocations: any[]): any[] {
if (!decoratorInvocations) {
return [];
}
return decoratorInvocations.map(decoratorInvocation => {
const decoratorType = decoratorInvocation.type;
const annotationCls = decoratorType.annotationCls;
const annotationArgs = decoratorInvocation.args ? decoratorInvocation.args : [];
return new annotationCls(...annotationArgs);
});
}
and then
this.encodedExampleHtml = getAnnotation(FooComponent).template;
Plunker Example
See also
Read and List all exports of an angular module
Example of how angular parses template