我使用“ exportGalleries()”将“ Galleries”常量的内容发送到API,但是我不知道如何更改服务器响应的显示,而不是“ gallery.component”组件中的本地内容< / p>
我将随时为您提供帮助
gallery.component
@Component({
selector: 'app-gallery',
templateUrl: './gallery.component.html',
styleUrls: ['./gallery.component.scss']
})
export class GalleryComponent implements OnInit {
private galleryId: string;
private gallery: IGallery;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.galleryId = this.route.snapshot.paramMap.get('galleryId');
this.gallery = Galleries.find((item: IGallery) => item.galleryId === this.galleryId);
console.log("GALL");
console.log(this.gallery);
}
}
constructor(private http: HttpClient) {
this.title='Galeria';
this.description='Wakacje';
this.galleries = [];
this.http.get('http://project.usagi.pl/gallery',
this.httpOptions).toPromise().then((response: IGallery[]) => {
console.log(response);
this.galleries = response;
});
this.searchValue ='';
}
ngOnInit() {
}
setSearchValue($event) {
console.log($event);
this.searchValue=$event;
}
exportGalleries() {
Galleries.forEach((gallery: IGallery) => {
delete(gallery.galleryId);
this.http.post('http://project.usagi.pl/gallery', gallery,
this.httpOptions).toPromise().then((response: IGallery) => {
console.log('success', response);
this.galleries.push(response);
}, (errResponse) => {
console.log('error', errResponse);
});
});
}