我在使用定制修饰器之前RC5版本的角度2,但现在它不可能(给出错误)。有没有解决这个问题的想法。继承装饰/ annonation in angular 2 ver 2.x.x
export function CustomComponent(annotation: any) {
return function (target: Function) {
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 extends AbstractComponent {
}
教程是在上面的代码https://medium.com/@ttemplier/angular2-decorators-and-class-inheritance-905921dbd1b7#.yqki96a5y 被Angular2的RC5版本之前工作正常
错误堆栈(NgModule前) - >
Error: (SystemJS) parentAnnotations is undefined
CustomComponent/<@http://localhost:3000/app/customCompo.js:8:13
[email protected]://localhost:3000/node_modules/reflect-metadata/Reflect.js:531:29
[email protected]://localhost:3000/node_modules/reflect-metadata/Reflect.js:115:20
__decorate<@http://localhost:3000/app/app.component.js:4:84
AppComponent<@http://localhost:3000/app/app.component.js:16:20
@http://localhost:3000/app/app.component.js:12:21
@http://localhost:3000/app/app.component.js:1:31
@http://localhost:3000/app/app.component.js:1:2
@http://localhost:3000/app/app.module.js:13:23
@http://localhost:3000/app/app.module.js:1:31
@http://localhost:3000/app/app.module.js:1:2
@http://localhost:3000/app/main.js:3:20
@http://localhost:3000/app/main.js:1:31
@http://localhost:3000/app/main.js:1:2
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:229:17
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:113:24
scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:509:52
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:262:21
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:151:28
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:405:25
ZoneTask/[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:336:25
Evaluating http://localhost:3000/app/app.component.js
Evaluating http://localhost:3000/app/app.module.js
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js
Stack trace:
(SystemJS) parentAnnotations is undefined
CustomComponent/<@http://localhost:3000/app/customCompo.js:8:13
[email protected]://localhost:3000/node_modules/reflect-metadata/Reflect.js:531:29
[email protected]://localhost:3000/node_modules/reflect-metadata/Reflect.js:115:20
__decorate<@http://localhost:3000/app/app.component.js:4:84
AppComponent<@http://localhost:3000/app/app.component.js:16:20
@http://localhost:3000/app/app.component.js:12:21
@http://localhost:3000/app/app.component.js:1:31
@http://localhost:3000/app/app.component.js:1:2
@http://localhost:3000/app/app.module.js:13:23
@http://localhost:3000/app/app.module.js:1:31
@http://localhost:3000/app/app.module.js:1:2
@http://localhost:3000/app/main.js:3:20
@http://localhost:3000/app/main.js:1:31
@http://localhost:3000/app/main.js:1:2
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:229:17
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:113:24
scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:509:52
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:262:21
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:151:28
[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:405:25
ZoneTask/[email protected]://localhost:3000/node_modules/zone.js/dist/zone.js:336:25
Evaluating http://localhost:3000/app/app.component.js
Evaluating http://localhost:3000/app/app.module.js
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js
昨天发布了Angular 2.3.0,它支持组件继承。 –
我尝试使用Angular 2.3.0,但没有运气@Tony – anshuVersatile