在Angular 2中没有导出成员'ROUTER_DIRECTIVES'和'provideRouter'

时间:2016-10-18 12:31:16

标签: angular angular-ui-router

我创建了一个新项目 angular-cli:1.0.0-beta.17 节点:4.1.0 npm:3.10.8

的package.json:

"dependencies": {
    "@angular/common": "~2.0.0",
    "@angular/compiler": "~2.0.0",
    "@angular/core": "~2.0.0",
    "@angular/forms": "~2.0.0",
    "@angular/http": "~2.0.0",
    "@angular/platform-browser": "~2.0.0",
    "@angular/platform-browser-dynamic": "~2.0.0",
    "@angular/router": "~3.0.0",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.17",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }

我在src / app下为路由器创建了一个新文件。代码是:

import { DirectoryComponent } from "./directory/directory.component";
import { HomeComponent } from "./home/home.component";
import { provideRouter } from '@angular/router';

const APP_ROUTES = [
    {path: 'directory', component: DirectoryComponent},
    {path: '', component: HomeComponent}
];

export const APP_ROUTES_PROVIDER = [
    provideRouter(APP_ROUTES)
];

我的main.ts文件是:

import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/';
import { APP_ROUTES_PROVIDER } from "./app/app.route";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule,[APP_ROUTES_PROVIDER]);

运行代码时出现错误:

ERROR in [default] /home/newAngularTwo/src/app/app.component.ts:3:9 
Module '"/home/sasireka/newAngularTwo/node_modules/@angular/core/index"' has no exported member 'ROUTER_DIRECTIVES'.

ERROR in [default] /home/newAngularTwo/src/app/app.route.ts:3:9 
Module '"/home/sasireka/newAngularTwo/node_modules/@angular/router/index"' has no exported member 'provideRouter'.

我犯的错误是什么?提前谢谢。

1 个答案:

答案 0 :(得分:5)

Angular 2现已发布。版本为' 2.0.0' 。在发行版中,没有provideRouterROUTER_DIRECTIVES。要在 Angular 2发布中进行路由,请参阅 Routing and Navigation