有两个 WP_Post Object (
[ID] => 778
[post_author] => 1
[post_date] => 2018-12-06 09:18:26
[post_date_gmt] => 2018-12-06 09:18:26
[post_content] => This is Solomon
[post_title] => Solomon Northup
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => solomon-northup
[to_ping] =>
[pinged] =>
[post_modified] => 2018-12-06 09:18:26
[post_modified_gmt] => 2018-12-06 09:18:26
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://localhost:8888/swart.shop/wp/?post_type=artists&p=778
[menu_order] => 0
[post_type] => artists
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
:Angular 6 Components
和DetailsProduct
。
当我编辑产品时,我将被重定向到有关该产品的详细信息页面。我的问题是,当我返回到“详细信息”时,已保存的新数据没有显示,而旧数据却显示了。
这是EditProduct
的代码:
EditProduct
这是EditProduct() {
let url = this.baseUrl + `/products/${this.id}`;
this.httpClient.put(url, JSON.stringify(query), httpOptions).subscribe(
response => {console.log(response); this.successMessage = true;},
err => { console.log(err); this.errorMessage = true;}
);
this.goToDetails();
}
goToDetails() {
this.router.navigate(['details-product/'+this.id]);
}
的代码:
DetailsProduct
这是我在路由模块中所拥有的:
getProductDetails() {
let url = this.baseUrl + `/products/${this.id}`
this.httpClient.get(url)
.subscribe(data => { this.oneProduct= data; })
}
任何想法在重定向到详细信息后如何获取新的保存数据(获取更新的数据)?在其他主题中找不到适合我的东西...
我遇到了这个topic about Resolver,但无法正确解决。任何帮助都非常感谢。
我使用了解析器,但未做任何更改。
答案 0 :(得分:0)
解决方案是:
EditProduct() {
let url = this.baseUrl + `/products/${this.id}`;
this.httpClient.put(url, JSON.stringify(query), httpOptions).subscribe(
response => {
this.goToDetails();
console.log(response); this.successMessage = true;},
err => { console.log(err); this.errorMessage = true;}
);
}
它在subscribe
内部调用重定向方法。很简单。