Collateral error not defined in Angular 2

My Angular 2 application gives me the following error:

angular2-polyfills.js: 138 Error: provide undefined main.ts

Here is my code:

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 have any ideas?

+4
source share
2 answers

Update

In Angular2 RC.4 and later provideare deprecated. Use the object literal syntax instead:

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


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

original

You need to import it. It is exported angular2/core:

import {PLATFORM_DIRECTIVES, provide} from 'angular2/core';
+5
source

You need to import it this way from the module angular2/core:

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

All Articles