アプリケーションのさまざまな部分で小さなビューを入力するために、ディレクティブとして使用している angular2 アプリケーションで小さなコンポーネントを作成しました。このディレクティブを使用しているコンポーネントでのみオプションを定義します。このディレクティブは常にオプションを持つことを想定しています。私の場合、サーバーからデータを取得するまでに時間がかかり、それから「someOptions」が定義されます。しかし、この「サンプル」コンポーネントはすぐにそれを期待していますが、どうすれば延期できますか? これをディレクティブとして使用し続ける方法を知っていますが、このディレクティブを使用しているコンポーネントでオプションが定義されている場合にのみアクティブにするように angular に指示しますか?
// the directive Im planning to use in differnt views
@Component({
selector: 'expml-comp'
})
export class Example1 {
@Input() options: any;
constructor() {}
ngOninit(){
//puting data from options to directive
}
}
//and the component where I want to use this directive:
@Component({
template: '<expml-comp [options] = 'definedData'></expml-comp>',
})
export class Example2 {
constructor() { }
private definedData:any;
//here I need to define the options but before the data comes from server //the Example1 dir is already activated
//and it didnt find definedData so it breaks
ngOnInit(){
//this.definedData=...
}
}