0
제품 목록이 있습니다. 각 제품은 id
및 description
입니다.productId가 다른 경우 이벤트를 덮어 쓰지 않으려면 어떻게해야합니까?
<div *ngFor="let product of products">
<input type="text" [ngModel]="product.description" (ngModelChange)="onEdit($event, product.id)">
</div>
editStream: EventEmitter<any> = new EventEmitter();
ngOnInit() {
this.editStream
.debounceTime(1000)
.distinctUntilChanged()
.mergeMap(x => Observable.of(x))
.subscribe(x => {
// based on product id, update its description in the database
});
}
private onEdit(description: string, id: string) {
this.editStream.emit({ description, id });
}
나는 하나 개의 제품의 설명을 편집 할 때 그것은 잘 작동합니다.
그러나 product1
의 설명을 편집 한 다음 바로 product2
의 설명을 편집하면 (시간 간격이 1 초 미만) product2
의 설명 만 업데이트됩니다.
나는 product2
님의 이벤트가 product1
님의 이벤트를 덮어 써서 한 곳에서만 구독하고 있기 때문에 발생했습니다.
어떻게 해결할 수 있습니까? 감사합니다
흠, 당신은 "각 제품에 대한 관찰 가능한 다른 '무엇을 의미합니까 ? –
각'product'에 대해 하나의'editStream'이 있습니다. –
'editStream'의 특정 번호 (제품 번호 기반)를 만드는 현명한 방법이 있습니까? editStream 배열을 사용합니까? –