我的welcome.component包含菜單和選項卡,一旦我點擊菜單項routerlink不會啓動一個新的請求,因此,tab組件不會重新加載。標籤組件被多個路由器鏈接調用,並且應該每次都重新加載。routerlink不能重新加載組件
welcome.component.html
<nav-menu></nav-menu>
<tab><tab>
navMenu.component.html
首次URL = http://localhost:xxxx/welcome
一旦我點擊從navMenu.component.html網址的項目不會改變 http://localhost:53620/tab/2
但是,tab.component需要觸發ngOnInt來重新載入id的數據2.
<ul class="list-unstyled list" *ngFor='let menu of menues'>
<li><a [routerLink]="['/tab',menu.LinkTabID]" class="anchorLink"><i class="icon-home scolor" ></i><font color="white">{{menu.Name}}</font></a></li>
</ul>
tab.component.html
<div class="row left" *ngFor='let control of tabControls; let i = index' style="padding-bottom:3px">
<div class="col-lg-2 text-left" style="border:0px dotted">
{{control.DropDownTitle}}:
</div>
<div class="col-lg-pull-3 text-left">
<select name="{{control.DropDownTitle}}" [(ngModel)]="selected[i]" style="width:80%" required>
<option value="" selected>Select</option>
<option *ngFor='let controlList of control.DropdownValues' [ngValue]="controlList.Value">
{{controlList.Value}}
</option>
</select>
</div>
</div>
app.module
RouterModule.forRoot([
{ path: 'welcome', component: WelcomeComponent},
{ path: '', redirectTo: 'welcome', pathMatch: 'full' },
{ path: '**', redirectTo: 'welcome', pathMatch: 'full' }
]),
navMenu.module
imports: [BrowserModule,
RouterModule.forChild([
{ path: 'tab/:id', component: WelcomeComponent}//,
]),
],
declarations: [NavMenuComponent],
providers: [NavMenuService],
exports: [NavMenuComponent]
tab.component
ngOnInit(): void {
this.linkTabID = +this._rout.snapshot.params['id']
if (isNaN(this.linkTabID))
{
this._appParams.GetDefaultTab(this.linkID, this.psnlUID)
.subscribe(data => {
this.linkTabID = data.result.LinkTabID;
this.GetControls(data.result.LinkTabID);
},
error => this.errorMessage = <any>error);
}
else
{
this.GetControls(this.linkTabID);
}
}
它只是重新加載,如果我這樣做是不好的,因爲頁面是空白,則URL永遠不會有,我用它來重新加載數據
<ul class="list-unstyled list" *ngFor='let menu of menues'>
<li><a (click)="onLinkClick"('/tab',menu.LinkTabID)" class="anchorLink"><i class="icon-home scolor" ></i><font color="white">{{menu.Name}}</font></a></li>
</ul>
navMenu.component的ID locLHOSTxxx /歡迎
onLinkClick(routeValue: string, tabID: string) {
this._router.navigate(['/tab', { id: tabID }]);
}
*****************更新************************* **************************
我摘下navMenu.module和tab.module並將th他們所有的app.module
RouterModule.forRoot([
{ path: 'welcome', component: WelcomeComponent },
{ path: 'tab/:id', component: WelcomeComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' },
{ path: '**', redirectTo: 'welcome', pathMatch: 'full' }
]),
,如果我做
{ path: 'tab/:id', component: TabComponent }
, 這將無法工作,因爲我將失去我的菜單項。 WelcomeComponent擁有組件選項卡和manu
仍然有一個問題,在這裏我看到重複在tab.component.html中的內容,如果你在子組件中有一個按鈕,使用你的plunker,第一次會加載你會看到一個按鈕,它自己很好,但是,如果你點擊菜單itiem你會看到兩個按鈕。所以你總是有重複的內容 – rgoal
你可以分叉的重擊,並在那裏重新創建問題,很難幫助沒有看到代碼:) – Alex
會做,謝謝 – rgoal