2016-03-30 12 views
2

angle 2.0.0-beta.8では、@Componentデコレータを拡張するカスタムデコレータをいくつか作成しました。私はこのコードを使用していたことを確認するためにangle2コンポーネントデコレータを拡張する

import {..., View } from 'angular2/core'; 

... 

export var MyCustomComponent:ComponentFactory = 
    <ComponentFactory>makeDecorator(MyCustomComponentMetadata, (fn:any) => fn.View = View); 

、角度2.0.0-beta.12で、「表示」デコレータはインポートがangular2」ため、エラーを投げるので、削除されました/ core 'にはエクスポートされたメンバー' View 'がありません。

カスタムコンポーネントデコレータを作成する方法は?

+1

を行うことができます。 @Component() '@Component()'を '@View()'の代わりに拡張することはできませんか? –

+0

'MyCustomComponent'デコレータを作成するには、第2引数として'(fn:any)=> fn.View = View'をとる 'makeDecorator'関数を呼び出す必要があります。これをコンパイルするには、 'View'をインポートする必要があります。 私は '@View()'デコレータを拡張するのではなく、 '@Component()'デコレータだけを拡張したいと思います。 – Gigitsu

+0

代わりに 'Component'を使用できません。ビューは存在しなくなりました。 –

答えて

4

あなたはそれはあなたが求めているものを私にはっきりしていない

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; 
    }; 
}; 
+0

私の要件に合わせてこのコードを少し修正して、うまくいくようです! 1つの質問、なぜ私は 'const _reflect:any = Reflect;'をする必要があるのですか? 'Reflect'だけ使うことはできますか? – Gigitsu

+1

確か....更新 – Luca