-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular build optimizer throws error on decorators #217
Comments
I was able to get an AOT build working on my hybrid application by reimplementing the class decorators as simple functions with a helper function in the actual decorator function. The Angular compiler didn't complain about the parameter decorators. export function annotateClass(target, annotationInstance) {
if (annotationInstance instanceof InjectableMetadata) {
annotationInstance.id = annotationInstance.id || globalKeyRegistry.get(target);
}
const annotations = reflector.ownAnnotations(target) || [];
annotations.push(annotationInstance);
reflector.registerAnnotations(annotations, target);
return target;
}
export function Directive(params) {
return function decorator(target) {
return annotateClass(target, new DirectiveMetadata(params));
}
} The only problem is that the key registry was throwing a type error because one of the internal types was not exported.
It should be possible to write a PR which re-implements the decorators in a way which satisfies the angular compiler. |
If anyones plagued by this.. we have a solution. It's NOT nice but we're actively moving from ng-metadata to ngUpgrade so it wasn't a big deal for us.
I would advocate finding a better solution as I personally hate this but it worked for us. |
The Angular CLI actually works pretty well with bundling hybrid ng-metadata applications. However the production build does not like 3rd party decorators (angular/angular#14323).
If possible ng-metadata should find a way to make the compiler happy and enable AOT on Angular components while keeping the Angular.js/ng-metadata components JIT.
The text was updated successfully, but these errors were encountered: