老师遇到问题了。
来源:3-9 改造股票管理应用

慕设计1238646
2018-08-05
因为用的是ng6,我看网上现在用pipe代替filter了。
目前问题是event.url只会等于dashboard,怎么都拿不到/stock。所以pageTitle一直只会显示Dashboard”。
我的代码
constructor(public router:Router) {
router.events.pipe(filter(
event=>event instanceof NavigationEnd)).subscribe((event:NavigationEnd)=>{
if(event.url =='/dashboard'){
this.pageTitle="This is pageTitle place for Dashboard";
this.pageDesc="this is pageDesc place Dashboard";
}else if(event.url.includes("/stock")){
this.pageTitle="this is title for STOCK";
this.pageDesc="this is Desc for stock";
}
})
}
下面是menu.component部分的
menu:Array<Menu>;
currentId:number;
constructor(public router:Router) { }
ngOnInit() {
this.menus=[
new Menu(1,'FIRST PAGE','dashboard'),
new Menu(2,'SECOND Page','stock')
];
}
nav(menu:Menu){
this.router.navigateByUrl(menu.link);
this.currentId=menu.id;
}
}
第二个问题是接下来在我点击了创建按钮,页面会先跳向/stock/0,然后立马就调回到/dashboard了。我也能看到stockForm.html显示出来了,但立马就跳回dashboard了。
这是path
const routeConfig: Routes=[
{path:'',redirectTo:'/dashboard',pathMatch:'full'},
{path:'dashboard',component:DashboardComponent},
{path:'stock',component:StockManageComponent},
{path:'stock/:id',component:StockFormComponent}
];
2回答
-
chicypaul
2019-01-02
你的第一段代码是在ContentComponent里面吗,pageTitle和pageDesc要显示在ContentComponent里,而不是在StockComponent或者StockFormComponent里
00 -
慕设计1238646
提问者
2018-08-05
我可以在网址栏里输入http://localhost:4200/stock/0,就可以停留在创建的那个page里,而且pageTitle和pageDesc也能正常显示出来。但在http://localhost:4200/stock中,pageTitle和pageDesc就不显示了。
00
相似问题
回答 3
回答 2