gerl
gerl

Reputation: 1181

angular2 - ROUTER_PROVIDERS is not defined

I have this code in my system.config.js when it comes to importing angular2's old router (the deprecated one).

'@angular/router-deprecated': 'npmcdn:@angular/router-deprecated@'+angularVersion,

I'm getting this error:

system.src.js:43 Uncaught (in promise) Error: ROUTER_PROVIDERS is not defined(…)

This is the plunkr here

How can I fix this?

Upvotes: 0

Views: 3802

Answers (2)

acdcjunior
acdcjunior

Reputation: 135802

Your plunker has several problems.

At app/index.ts:

  • Add the imports:

    import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
    import { HashLocationStrategy, LocationStrategy } from '@angular/common';
    import { provide } from '@angular/core';
    
  • Not mandatory, but you should remove the .ts extension:

    import { App } from './app2.ts';
    

    Should really be:

    import { App } from './app2';
    

At app/home.ts

  • Add the path to the templateUrl:

    templateUrl: './home.html'
    

    Becomes:

    templateUrl: './app/home.html'
    

At app/add_developer.ts

  • Also add the path to the templateUrl:

    templateUrl: './add_developer.html'
    

    Becomes:

    templateUrl: './app/add_developer.html'
    

General: Update *ngFor notation

  • Consider updating the *ngFor notation to the latest. You are using it in several places. Use let instead of #. For instance, at app/home.html:

    <tr *ngFor="#dev of getDevelopers()">
    

    Should be

    <tr *ngFor="let dev of getDevelopers()">
    

Click here for your updated plunker (including the *ngFor changes).

Upvotes: 1

Sanket
Sanket

Reputation: 20037

Add below line in index.ts

import { ROUTER_PROVIDERS, RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated';

And add providers: [ROUTER_PROVIDERS] in you app2.ts file.

Upvotes: 0

Related Questions