【发布时间】:2018-01-16 07:00:09
【问题描述】:
我正在学习角度,在我的项目中,我创建了 routerLink 的导航栏,用于导航到页面。
<ul>
<li> <a href="#">Home</a></li>
<li> <a href="#" [routerLink]="['/about']" >about us</a></li>
<li> <a href="#" [routerLink]="['/contact']" >contact us</a></li>
</ul>
这是我的app.module.ts,我在其中设置了导航路由器。
imports: [
BrowserModule,
HttpModule,
RouterModule.forRoot([
{ path:"**", component: HomeComponent,pathMatch: 'full' },
{ path:"about", component: AboutComponent },
{ path:"contact" , component: ContactComponent }
])
],
所以,当我运行它时,它运行完美,首先进入主页但是当我点击关于我们页面和查询字符串路由器中的联系页面时会改变但内容不会改变,主页的内容与它相同是,这是我的主页和关于我们的页面。
this is m home.component.ts
constructor(private _avRoute: ActivatedRoute,
private _cmsService: CmsService,
private _router: Router) { }
ngOnInit() {
this.getConsultHome();
}
getConsultHome(){
this._cmsService.getcmsConsultHome()
._router.params.subscribe(data =>{ this.data = data }
, error => this.errorMessage = error);
}
这是我的about.component.ts
constructor(private _avRoute: ActivatedRoute,
private _cmsService: CmsService,
private _router: Router) {
}
ngOnInit() {
this._cmsService.getcmsConsultAbout()
.subscribe(data =>{ this.data = data }
, error => this.errorMessage = error);
}
请任何人帮助我,我被困在这个问题上。我看到了很多与此相关的问题,但没有那么有用并解决我的问题,提前致谢
【问题讨论】:
-
添加代码而不是截图。
-
@Aravind,好的。我做到了,请再检查一次
-
控制台有错误吗?
-
@AkashAgrawal no