0
我使用的是angular2 rc.6。我正在開發一種類似於亞馬遜搜索的搜索應用程序,用於顯示產品。 我的問題是,當我路由到不同的參數相同的網址我的組件不會得到更新。但是當我點擊頁面的任何地方或按任意鍵我獲得更新的數據Angular 2 rc.6導航到相同的路線不刷新組件
我的依賴關係是: -
"dependencies": {
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/core": "2.0.0-rc.6",
"@angular/forms": "2.0.0-rc.6",
"@angular/http": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"@angular/router": "3.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.6",
"systemjs": "0.19.27",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.11",
"zone.js": "^0.6.17",
"angular2-in-memory-web-api": "0.0.18",
"bootstrap": "^3.3.6"
},
我的路由配置是: -
const searchRoutes: Routes = [{ path: 'home',component: Dashboard,},
{ path: 'titleList/:titleName',component: TitlesListDetails},]
export const searchRouting = RouterModule.forRoot(searchRoutes);
路線時使用以下部件
最後TitlesListDetails成分: -
constructor(private searchService : SearchService,
private route: ActivatedRoute,
private router: Router){
this.route.params.subscribe(params => { this.searchService.fetchAllSearchData(params['titleName'],localStorage.getItem("sortTerm")).subscribe(searchResult => {
this.searchResult = searchResult;
this.products=searchResult.products;
},error => console.log("Error while fetching Products Details")
);
});
}
我在構造函數中訂閱的路由參數。 任何機構可以建議如何更新TitlesListDetails
感謝答覆。我會檢查 – Vicky3D
你能分享一下package.json文件嗎? – Vicky3D
我編輯我的答案與提取 –