Hammer Hammer - 1 year ago 94
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 Source


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

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

  providers: [{provide: SomeService, useClass: SomeOtherService}], 


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

import {PLATFORM_DIRECTIVES, provide} from 'angular2/core';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download