offer$ observable 正在通过异步管道和 *ngfor 推送到子组件。当它通过发布请求更新时,不会在 DOM 上呈现更改。如果我使用一个数组并订阅获取使用异步管道的请求,它可以工作......不知道为什么。
应用组件.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
title = 'promoapp';
offers$:Observable<Offer[]>
constructor(private offerservices : OffersService){}
ngOnInit(): void {
this.offers$ = this.offerservices.loadOffers()
}
onOfferSubmitted(offer:Offer){
this.offerservices.PostRequest(offer);
this.offers$ = this.offerservices.loadOffers()
}
}
html
<app-offercreation (OfferSubmitted)="onOfferSubmitted($event)"></app-offercreation>
<app-offerdisplay *ngFor="let offer of (offers$ | async)" [offer]="offer"></app-offerdisplay>
子组件
@Component({
selector: 'app-offerdisplay',
templateUrl: './offerdisplay.component.html',
styleUrls: ['./offerdisplay.component.scss'],
})
export class OfferdisplayComponent implements OnInit {
@Input()
offer:Offer
constructor() { }
ngOnInit(): void {
}
}
谢谢