見大量的研究後,我可以解決使用路由器問題。現在應用程序非常快。
app.component.ts:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
templateUrl: 'app/app.component.html',
selector: 'my-app'
})
export class AppComponent {
constructor(
private router: Router) {
}
handleChange(e) {
let index = e.index;
let link;
switch (index) {
case 0:
link = ['/home'];
break;
case 1:
link = ['/hierarquia'];
break;
case 2:
link = ['/config'];
break;
}
this.router.navigate(link);
}
}
app.component.html:
<div>
<p-tabView (onChange)="handleChange($event)">
<p-tabPanel header="Home" leftIcon="fa-bar-chart-o"></p-tabPanel>
<p-tabPanel header="Hierarquia" leftIcon="fa-sitemap"></p-tabPanel>
<p-tabPanel header="Configurações" leftIcon="fa-cog"></p-tabPanel>
</p-tabView>
</div>
<router-outlet></router-outlet>
app.route.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppHome } from './app.home';
import { AppTree } from './app.tree';
import { AppConfig } from './app.config';
const routes: Routes = [
{
path: 'home',
component: AppHome
},
{
path: 'hierarquia',
component: AppTree
},
{
path: 'config',
component: AppConfig
},
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routedComponents = [AppHome, AppTree, AppConfig];
app.module.ts:
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
import 'rxjs/add/operator/toPromise';
import { AppConfig } from './app.config';
import { AppHeader } from './app.header';
import { AppHome } from './app.home';
import { AppTree } from './app.tree';
import { AppComponent } from './app.component';
import { AppRoutingModule, routedComponents } from './app.route';
import { InputTextModule, DataTableModule, ButtonModule, DialogModule, TabViewModule, ChartModule, TreeModule, GrowlModule, InputSwitchModule, BlockUIModule, InputMaskModule, DropdownModule } from 'primeng/primeng';
@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpModule, AppRoutingModule, InputTextModule, DataTableModule, ButtonModule, DialogModule, TabViewModule, ChartModule, TreeModule, GrowlModule, InputSwitchModule, BlockUIModule, InputMaskModule, DropdownModule],
declarations: [AppHeader, AppComponent, AppHome, AppTree, AppConfig, routedComponents],
bootstrap: [AppHeader, AppComponent]
})
export class AppModule { }
謝天謝地! =]
你是怎麼知道的? –
嗨,@羅曼C。抱歉。我怎麼知道什麼? –
*在加載tabView的同時,我的三個組件(home,tree和config)被加載* - 你是怎麼知道的? –