Hammer Hammer - 4 months ago 30
AngularJS Question

provide is not defined

My AngularJS2 gives me

angular2-polyfills.js:138 Error: provide is not defined main.ts
. my codes is:

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})]);


Anyone has any idea?

Answer

update

In Angular2 RC.4 and later provide is deprecated. Use object literal syntax instead:

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


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

original

You need to import it. It's exported by angular2/core:

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