0
在更改JavaScript值後,我在輸入字段中遇到了RXjs'distinceUntilChanged問題。Angular 2 | RXjs在更新視圖後出現distinctUntilChanged問題
重現步驟:
集文字 「一」 裏面輸入
點擊刪除按鈕>>作爲導致的輸入是空的,有使用JavaScript的
- 在輸入內再次設置「a」
- 再次點擊刪除按鈕。但現在輸入保持「a」值
如果我們插入另一個不同於'a'的值,它將起作用。 當然,如果我從我的observable中刪除distinceUntilChanged,它也會起作用。
代碼片段:
@Component({
selector: 'app',
template: `
<input #input [value]="value ? value : ''" (input)="filter$.next(input.value)">
{{val}}
<div>
<button (click)=remove()>Remove</button>
</div>
`
})
export class App {
filter$ = new Subject();
val:string;
value:string;
constructor() {
}
ngOnInit(): void {
this.filter$
.distinctUntilChanged()
.subscribe((value) => {
this.val = value;
this.value = value;
}));
}
remove(){
console.log('test');
this.value = "";
this.val = "";
}
}
我創建了我的問題Plunker例如: