升级到Angular 2 RC后的路由器错误

时间:2016-05-04 16:25:58

标签: angular

app/main-menu.component.ts(18,24): error TS2339: Property 'isRouteActive' does not exist on type 'Router'.
app/main-menu.component.ts(18,50): error TS2339: Property 'generate' does not exist on type 'Router'.

我的主菜单组件:

import {ROUTER_DIRECTIVES, Router} from '@angular/router';

...
directives: [ROUTER_DIRECTIVES],

export class MainMenuComponent {    

        constructor(private router: Router, private JwtService:JwtService){}

public isRouteActive(route) {
    return this.router.isRouteActive(this.router.generate(route))
}

}

我检查了角度2路由器文档,但一切都是一样的,为什么我会收到这个错误?

1 个答案:

答案 0 :(得分:2)

你正在使用新的路由器" old"代码。

更改

import {ROUTER_DIRECTIVES, Router} from '@angular/router';

import {ROUTER_DIRECTIVES, Router} from '@angular/router-deprecated';

另见Angular2 router-deprecated dependencies not being loaded