1
私のアプリには2つのフォームがあります。選択されたドロップダウン値に基づいて、それぞれがユーザーに表示されます。rxjsでサブスクリプションを停止/開始するには?
<select (change)="change($event)">
<option value="0">New</option>
<option value="1">Existing</option>
</select>
次に.TSファイルで:
ngAfterViewInit() {
this.existingForm.valueChanges.subscribe(p => {
//code
});
this.newForm.valueChanges.subscribe(p => {
//code
});
}
change($event) {
if ($event.target.value == 0) {
//pause newForm subscription
//start existing subscription
}
if ($event.target.value == 1) {
//pause existing subscription
//start newform subscription
}
}
私はサブスクリプションAPIをチェックしていましたが、もう一度「開始」する「購読」メソッドはありません。 – gog
@ggui Observableを再度登録し直すことができます。私の更新された答えを見てください。 – Pengyy