this.skusChangeSubscription = this.productForm.get('skus').valueChanges
.pipe(debounceTime(600)).subscribe(skusValue => {
console.log('SKUS: ', skusValue);
...
...
});
我需要代码来直接运行这个订阅方法一次,直到值发生变化。它在值更改时起作用,但在值更改之前订阅时不起作用。我需要在订阅时运行一次。
尝试使用startWith
运算符。在从可观察的源发出之前,它首先发出指定为参数的项。
this.skusChangeSubscription = this.productForm.get('skus').valueChanges
.pipe(
startWith(this.productForm.get('skus').value),
debounceTime(600)
)
.subscribe(skusValue => {
console.log('SKUS: ', skusValue);
...
...
});
试试这个:
this.skusChangeSubscription = this.productForm.get('skus')
.pipe(take(1)).subscribe(skusValue => {
console.log('SKUS: ', skusValue);
...
...
});