我想使用GalleryService
方法来更新update
中有关该帖子的信息。当我单击Edit
按钮时,我转到所选帖子的地址,其数据在输入字段中。在更改字段中的内容并单击Update Post
按钮以更改帖子后,我的表单将关闭,但不会发生任何更改。也没有错误,请告诉我我的问题是什么,并帮助解决它。
按钮Edit
:
GalleryItemComponent
<a class="btn btn-success ed" [routerLink] = "['/galleryEdit', pic.id]" (click)="editPost(pic)">Edit</a>
中的表格:
GalleryEditComponent
<form [formGroup]="angFormEd" novalidate>
<input type="text" class="form-control" formControlName="titleEd" #titleEd
[(ngModel)]="post.title"/>
<input type="url" class="form-control" formControlName="urlEd" #urlEd pattern="https?://.+"
title="Include http://" [(ngModel)]="post.url"/>
<button (click)="updatePost(titleEd.value, urlEd.value)"
[disabled]=" angFormEd.invalid">
btn btn-primary">Update Post</button>
</form>
:
GalleryEditComponent.ts
** export class GalleryEditComponent implements OnInit {
post: Picture;
constructor(private fb: FormBuilder,
private route: ActivatedRoute, private galleryService: GalleryService) {
}
ngOnInit() {
this.editPost();
}
editPost(): void {
this.route.params.subscribe(params => {
this.galleryService.edit(params['id']).subscribe(res => {
this.post = res;
})
})
}
updatePost(title: string, url: string): void {
this.route.params.subscribe(params => {
this.galleryService.update(title, url, params['id']);
});
}
}
:**
GalleryService.ts