在angular2中重新渲染导航栏

时间:2016-01-26 08:56:12

标签: angular angular2-routing

使用angular2构建应用时遇到问题。
我在两个数组中定义//Action in B controller public function beforeFilter() {//not completelly necessary but handy. You can recover directly the data //from session in the action if($this->Session->check('previousPageInfo')) {$this->data = $this->Session->read('previousPageInfo')}; parent::beforeFilter(); } public function processFromPreviousPage() { //do what ever you want to do. Data will be in $this->data or // if you like it better in $this->request->data $this->processUserData($this->request->data); //... }

appRoutes.ts

routes

App.ts:在var beforeLogin = [ { path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true }, { path: '/login', name: 'Login', component: LoginComponent }, { path: '/**', name: ' ', redirectTo: ['Home'] } ], afterLogin = [ { path: '/about', name: 'About', component: AboutComponent, useAsDefault: true }, { path: '/**', name: ' ', redirectTo: ['About'] } ]; 注册routes,将RouterConfig注册为NavbarComponent

derective

navbar.ts:

@Component({
    selector: 'main-app',
    templateUrl: './src/app/app.html',
    directives: [RouterOutlet, NavbarComponent],
    pipes: [TranslatePipe]
})

@RouteConfig(APP_ROUTES) //register routes config

navbar.html

export class NavbarComponent {
    private routeList: RouteDefinition[];

    constructor() {
        this.routeList = APP_ROUTES;
        this.isLogin = Security.getLogin();
    }

    logout() { 
        this.updateNavbar();    
    }

    updateNavbar() {

    }
}

我希望<ul class="nav navbar-nav"> <li *ngFor="#route of routeList"><a [routerLink]="[route.name]">{{route.name}}</a></li> </ul> 可以在登录/注销应用时重新呈现。登录后无法在navbar路线中加载路线(重定向到beforeLogin等等),反之亦然 Home:加载应用时显示在beforeLogin navbar:登录后显示在afterLogin

对我而言,谢谢。

0 个答案:

没有答案