これは非常に単純な質問ですが、私はAngular2の新機能ですが、良い例とチュートリアルを見つけることができますが、時にはもう少し説明が必要です。子コンポーネントで同じObservableを購読するAngular2/TypeScript
だから私は持っていると観測可能な、すべての非常に頻繁に更新されたのcompoentを持っています。私は本当にここに私のコードを編集しているが、ここに私の問題の肉があり、あなたは私が直接の子ではなく、おそらくにダウン深くネストされていないことがあり、子コンポーネントを持っている今
@Component({
selector: 'product-profile',
templateUrl: './product-profile.component.html',
styleUrls: ['./product-profile.component.scss']
})
export class ProductProfileComponent {
// I have ommitted so much code here....
product: Observable<Product>;
constructor(
private store: Store<any>
) {
this.product = this.store
.let(getProductStore)
.let(getProductProfile);
this.product
.select((product: Product) => product && product.id)
.subscribe(productId => this.productId = productId
});
}
// I have omitted so much code here....
}
product
と呼ばれる観察可能に気づくでしょう3番目または4番目のレベルのコンポーネントのようなもの
@Component({
selector: 'product-footer',
templateUrl: './product-footer.component.html',
styleUrls: ['./product-footer.component.scss']
})
export class ProductFooterComponent {
// this is the same Observable/property from the parent
// when there is a change in the parent I want to update the property below...
product: Observable<Product>;
constructor(){}
}
ここで私は何をすべきか分かりません。親の製品プロパティの値が変更された場合、どのように子コンポーネントの製品プロパティを更新しますか? @Input()
を使用する必要がありますか?私はこれについて考えましたが、関係が直接の親子関係ではないので、これがどのように機能するのかは分かりません。 EventEmitter
のようなものを使うべきですか?どんなアドバイス/リンクも高く評価されていますが、現在は少し失われており、私のリソースは当てはまりません!
で行くだろう何/ *作成観測可能* /;?変数と同じに設定するだけですか?あなたのパターンに従えば、私は子コンポーネントから "undefined"を購読します。 – Anthony