为什么数据更新方法不起作用?

时间:2018-10-08 10:26:03

标签: javascript angular typescript json-server

我想使用GalleryService方法来更新update中有关该帖子的信息。当我单击Edit按钮时,我转到所选帖子的地址,其数据在输入字段中。在更改字段中的内容并单击Update Post按钮以更改帖子后,我的表单将关闭,但不会发生任何更改。也没有错误,请告诉我我的问题是什么,并帮助解决它。

组件{{1}中的

按钮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

0 个答案:

没有答案