2016-06-28 58 views
2

當我在bootstrap中使用provideRouter函數時,我得到錯誤router_1.provideRouter is not a function角度2路由器錯誤:router_1.provideRouter不是函數

angular2-polyfills.js:349 Error: router_1.provideRouter is not a function(…)

這裏是我的boot.ts代碼:

import {bootstrap}      from 'angular2/platform/browser'; 
import {AppComponent}     from './app.component'; 
import {Dashboard1Component}   from './dashboard1.component' 
import {TextAreaComponent}    from './textArea.component' 
import { provideRouter }    from 'angular2/router'; 
const router =[ 
    { path: 'link1', component: TextAreaComponent }, 
    { path: 'link2', component: Dashboard1Component } 
]; 

bootstrap(AppComponent,[provideRouter(router)]).catch(err => console.error(err));; 

,這裏是我的index.html中的腳本加載的應用程序和庫,而無需使用system.config.js:

<!-- Angular 2 beta parts --> 
<script src="http://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script> 
<script src="http://code.angularjs.org/tools/typescript.js"></script> 
<script src="http://code.angularjs.org/2.0.0-beta.17/angular2-polyfills.js"></script> 
<script src="http://code.angularjs.org/2.0.0-beta.17/Rx.js"></script> 
<script src="http://code.angularjs.org/2.0.0-beta.17/angular2.dev.js"></script> 
<script src="http://code.angularjs.org/2.0.0-beta.17/router.dev.js"></script> 


<!-- 2. Configure SystemJS --> 
<script> 
    System.config({ 
    transpiler: 'typescript', 
    typescriptOptions: { emitDecoratorMetadata: true }, 
    packages: {'components': {defaultExtension: 'ts'}} 
    }); 
    System.import('components/boot') 
     .then(null, console.error.bind(console)); 
</script> 

請注意,我的代碼中沒有router_1變量。我很欣賞指導。謝謝。

回答

1

provideRouter用隨RC.3新的路由器引入,是不是在beta.17

參見https://angular.io/docs/ts/latest/guide/router.html

+0

你能指導我在哪裏可以找到RC.3版本的路由器嗎? 根據https://www.npmjs.com/package/angular2 beta 17是最新版本,我也無法在其他CDN中找到RC3版本。 –

+0

命名空間已從'angular2'更改爲'@ angular' RC.0 –

+0

'npm install --save @ angular/core @ angular/compiler @ angular/common @ angular/platform-b​​rowser @ angular/platform-b​​rowser-動態[email protected] zone.js @ 0.6.12' https://github.com/angular/angular/blob/master/CHANGELOG.md#200-rc0-2016-05-02 –

0

這個固定我的問題可用,別人說,該模塊是包,所以你必須更新: systemjs.config.js

var map = { 
    '@angular/router': 'node_modules/@angular/router' 
} 

app.routes.ts

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