Angular2:没有被调用的ngOnit

时间:2016-08-04 03:12:11

标签: typescript angular angular2-routing

使用angular 2.0.0-rc.4和路由器3.0.0-beta.2。当我导航到路线或进行新的重新加载时,不会调用ngOnInit。如果我单击与当前路径匹配的锚标记,则调用ngOnInit。我做错了什么?

轮廓routes.ts

import { RouterConfig } from '@angular/router';

import { ProfileComponent } from './profile.component';
import { ProfileFormComponent } from './profile-form.component';

export const ProfileRoutes: RouterConfig = [
    {
        path: 'profile',
        component: ProfileComponent,
        children: [
            {
                path: '',
                component: ProfileFormComponent             
            }
        ]
    }
];

轮廓component.ts

import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';

import { ProfileFormComponent } from './profile-form.component';

@Component({
    selector: 'profile',
    template: '<router-outlet></router-outlet>',
    directives: [ROUTER_DIRECTIVES]
})

export class ProfileComponent {

}   

轮廓form.component.ts

import { Component, OnInit } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';

@Component({
    selector: 'profile-form',
    templateUrl: 'app/profile/profile-form.component.html',
    directives: [ROUTER_DIRECTIVES] 
})

export class ProfileFormComponent implements OnInit {           

    ngOnInit() {        
        console.log('Onit'); //this isn't called
    }

}

0 个答案:

没有答案