2016-04-25 106 views
4

我的AngularJS2給我angular2-polyfills.js:138 Error: provide is not defined main.ts。我的代碼是:提供未定義

import {bootstrap} from 'angular2/platform/browser'; 
import {AppComponent} from './app'; 
import {ROUTER_PROVIDERS,ROUTER_DIRECTIVES} from 'angular2/router'; 
import {PLATFORM_DIRECTIVES} from 'angular2/core'; 


bootstrap(AppComponent, [provide(PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi:true})]); 

任何人有什麼想法?

回答

4

更新

在Angular2 RC.4後來provide已經過時了。使用對象文本語法來代替:

bootstrap(AppComponent, [{provide: SomeService, useClass: SomeOtherService}]) 


@Component({ 
    providers: [{provide: SomeService, useClass: SomeOtherService}], 
    ... 
}) 

您需要將其導入。它由angular2/core導出:

import {PLATFORM_DIRECTIVES, provide} from 'angular2/core'; 
1

你需要這樣從angular2/core模塊導入:

import {provide, PLATFORM_DIRECTIVES} from 'angular2/core'; 
相關問題