Angularjs 带有异步管道的Angular*ngfor在api post请求后不更新DOM
offers$observable通过异步管道和*ngfor推送到子组件。当它通过post请求更新时,更改不会在DOM中呈现。如果我使用一个数组并订阅获取请求,而不是使用异步管道并通过异步管道进行观察,它就会工作……不知道为什么 App Component.tsAngularjs 带有异步管道的Angular*ngfor在api post请求后不更新DOM,angularjs,express,ngfor,async-pipe,Angularjs,Express,Ngfor,Async Pipe,offers$observable通过异步管道和*ngfor推送到子组件。当它通过post请求更新时,更改不会在DOM中呈现。如果我使用一个数组并订阅获取请求,而不是使用异步管道并通过异步管道进行观察,它就会工作……不知道为什么 App Component.ts @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], })
@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()
}
}
感谢我通过修改onOfferSubmitted方法并订阅post请求,解决了这个问题
onOfferSubmitted(offer:Offer){
this.offerservices.PostRequest(offer).subscribe(()=>{
this.offers$=this.offerservices.loadOffers()
})
@Component({
selector: 'app-offerdisplay',
templateUrl: './offerdisplay.component.html',
styleUrls: ['./offerdisplay.component.scss'],
})
export class OfferdisplayComponent implements OnInit {
@Input()
offer:Offer
constructor() { }
ngOnInit(): void {
}
}
onOfferSubmitted(offer:Offer){
this.offerservices.PostRequest(offer).subscribe(()=>{
this.offers$=this.offerservices.loadOffers()
})