TypeError:无法读取未定义的属性(读取“deletePostById”)
我的代码有什么问题?
HTML
<div class="row post" *ngFor="let post of posts">
<div *ngIf="isAdminIn" ngbDropdown class="float-right" class=" col-md-1">
<button (click)="deletePost(post.id)">Delete</button>
</div>
</div>
.ts
deletePost(id:number): void {
this.postService.deletePostById(id).subscribe(data => {
this.router.navigateByUrl('');
}, error => {
throwError(error);
})
}
服务.ts
deletePostById(id: number): Observable<any> {
return this.http.delete('http://localhost:8080/api/posts/' + id);
}
你postService
是未定义的。您是否将其注入到组件的构造函数中?
constructor(
private postService: PostService
) {}
??
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句