扩展angular2组件装饰器 [英] Extending angular2 component decorator
本文介绍了扩展angular2组件装饰器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用angular 2.0.0-beta.8,我创建了几个自定义装饰器,它们扩展了@Component装饰器.
With angular 2.0.0-beta.8 I've created a couple of custom decorator that extends the @Component decorator.
为了使我使用此代码,
import {..., View } from 'angular2/core';
...
export var MyCustomComponent:ComponentFactory =
<ComponentFactory>makeDecorator(MyCustomComponentMetadata, (fn:any) => fn.View = View);
现在,对于角度为2.0.0-beta.12的版本,视图"修饰符已被删除,因此导入会引发错误,因为角度2/核心"没有导出成员视图".
Now, with angular 2.0.0-beta.12, the 'View' decorator has been dropped so the import throw an error because 'angular2/core' has no exported member 'View'.
我应该如何创建自定义组件装饰器?
How I'm supposed to create a custom component decorator?
推荐答案
您可以
import {Component} from 'angular2/angular2';
import {MyCustomComponentMetadata} from ...;
export function MyCustomComponent(config: MyCustomComponentMetadata) {
return function(cls) {
var annotations = Reflect.getMetadata('annotations', cls) || [];
annotations.push(new Component(config));
Reflect.defineMetadata('annotations', annotations, cls);
return cls;
};
};
这篇关于扩展angular2组件装饰器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文