1
オペレータチェーン内で購読する前に条件を確認するにはどうすればよいですか?私はこのようなものを持っています。条件が満たされた場合に購読するreturn/exit rxjs
parentElem:boolean = false; // the parent elem show/hide;
// inside the ngAfterViewInit();
this.myForm.get('grandParent').valueChanges
//.takeWhile(...) no idea if it works with my condition or not.
//.skipWhile(...) no idea if it works with my condition or not.
.map(val => {
// i want to return from here if some condition is falsy;
if(!this.parentElem) return; // how can i return/exit from here?
// otherwise return that service and subscribe;
this.$parent.empty();
return this.dropdownProvider.getParent(val);
}).subscribe(service => service.subscribe(data => {
data = data.map(d => {
return { id: d.text, text: d.text
};
});
this.initParent(data);
}));
この関数は、プロパティ値を変更します。
onDropdownChange(event:Event)
{
this.parentElem = event.value === 'parent';
}
HTML要素
<select (change)="onDropdownChange($event)">
...
</select>
はすでに.takeWhile(...)
& .skipWhile(...)
と試みたが、私はそれが私の条件で動作するかどうかということはわかりません。
私はあなただけ '... valueChanges.filter(()=> this.parentElem)を使用することができると思いますか...'? – martin
@martinが期待通りに働いてくれてありがとう。 – Robin