rc1-router "Kein provider für Router"

Dies ist ein follow-up-post für einen Fehler, kommen nach @Shuhei half mir, mich gelöst config.js problem Winkel-2 rc-router angular2-polyfills.js:349 Fehler

Dies ist meine app.Komponente.ts

import { Component,provide }       from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES,Router } from '@angular/router-deprecated';

import { HeroShellComponent } from '../apps/hero/hero-shell.component';
import {HomeComponent} from '../home/home.component';

import {Login} from '../login/auth.component';
import {Authentication} from '../login/auth.service';
import {isLoggedin}  from '../login/auth.isLoggedin';

@Component({
  selector: 'my-app', 
  templateUrl: 'app/appshell/app.component.html',
  styleUrls: ['app/appshell/app.component.css'],
  directives: [ROUTER_DIRECTIVES],
})

@RouteConfig([
    {
        path: '/app/apps/hero/...',
        name: 'Hero Sample',
        component: HeroShellComponent,
    },
    { path: '/app/apps/testapp1', name: 'Testapp1', component: HomeComponent },
    { path: '/', redirectTo: ['Login'] },
    { path: '/home', name: 'Home', component: HomeComponent },
    { path: '/login', name: 'Login', component: Login, useAsDefault: true },   
])
export class AppComponent {

  title = 'Apps';

  constructor(public _auth: Authentication, 
              public router: Router
              ) {}  

  onLogout() {

    this._auth.logout();
    this.router.navigate(['/Login']);
  }

}

Alle anderen Komponenten injiziert Router über Konstruktor wie oben. Router ist sicher, sofern.

path: '/app/apps/hero/...'

ist für die Kind-router umleiten.

Die Fehler, die ich habe ist

browser_adapter.ts:78 EXCEPTION: Error: 
Uncaught (in promise): EXCEPTION: Error in :0:0 
ORIGINAL EXCEPTION: No provider for Router!. 

ORIGINAL STACKTRACE: Error: DI Exception 
at NoProviderError.BaseException [as constructor] (npmcdn.com/@angular/[email protected]/src/facade/…) 
at NoProviderError.AbstractProviderError [as constructor]

Wenn der gleiche code war in der beta, was könnte er nicht in der RC1-router-veraltet?

Update: index.html

<html>
  <head>
    <base href="/">

    <title>My Tests</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">    
    <link  href="/app/public/css/styles.css">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-sham.min.js"></script>           
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.25/system-polyfills.js"></script>      
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>

    <script src="https://code.angularjs.org/2.0.0-beta.17/angular2-polyfills.js"></script>
    <script src="https://code.angularjs.org/tools/system.js"></script>
    <script src="https://code.angularjs.org/tools/typescript.js"></script>
    <script src="/app/systemjs.config.js"></script>

    <script>
      System.import('app/main').then(null, console.error.bind(console));
    </script>
  </head>
  <body>
    <my-app>Loading...</my-app>
    <script>document.write('<base href="' + document.location + '" />');</script>
  </body>
</html>
Tritt der Fehler wirklich auftreten auf AppComponent? Würde der Geist Sie erstellen ein MCV Beispiel auf plunker, so dass die Menschen basteln kann. stackoverflow.com/help/mcve

InformationsquelleAutor Shawn | 2016-05-07

Schreibe einen Kommentar