2016-05-24 5 views
3

私はButtonComponentと呼ばれるコンポーネントがあります。コンポーネントの角2命令は、ng-contentをオーバーライドしますか?

import { Component } from "angular2/core"; 

@Component({ 
    selector: 'btn', 
    template: '<div class="btn"><ng-content></ng-content></div>' 
}) 
export class ButtonComponent { } 

と指令:

import { Directive, Input } from 'angular2/core'; 

@Directive({ 
    selector: 'btn[dialog-data]' 
}) 
export class DialogButtonDirective { 
    @Input('dialog-data') 
    public dialogData: any; 
} 

をしかし、私はこのようにそれを使用しようとします

<btn [dialog-data]="dart()">DART</btn> 

次にボタンが内側に何もありませんそれの。 なぜですか?私がこの指令を使用していないときは、すべてが問題ありません。

+0

Plunkerで再生しようとすることはできますか? –

答えて

2

OK、少し混乱しますが、私は答えを見つけました。 DialogBu​​ttonDirectiveがButtonComponentの前に '指示文'フィールドで宣言されているため、このコードは機能しません。これに

directives: [DialogButtonDirective, ButtonComponent] 

は、だから私は、これを変更した

directives: [ButtonComponent, DialogButtonDirective] 

そして、それは問題を解決しました。ありがとう!

+0

私は元の原因が他の場所(使用しているブラウザやサーバーの一部のキャッシュ)になると予想していましたが、この変更によって適切な再読み込みが行われました。この変更は絶対に意味がありません( 'DialogBu​​ttonDirective'と' ButtonComponent'がプロバイダの配列ではなくクラスである限り) –

+0

このエラーはPlunkerで再現できませんが、実際にはアプリケーションで発生します。サーバー(ライトサーバー)。私は知っている、これは狂気かもしれないが、私のソリューションは実際に動作します。 – Iceekey

関連する問題