I ran into a problem using the new Angular 2 RC5 router (version of the RC1 router).
Here is the log I get from the dev console:
EXCEPTION: Error in /templates/app.component.html:2:0 ORIGINAL EXCEPTION: No provider for Router!
This is what my app.modules.ts looks like:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { RouterModule } from '@angular/router'; import { AppComponent } from './components/app.component'; import { routing } from './app.routes'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule, RouterModule, FormsModule, HttpModule, routing], bootstrap: [AppComponent], }) export class AppModule {}
Here is my boot.ts file:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule);
My app.routes.ts file ...
import { Routes, RouterModule } from '@angular/router'; // Components import { HomeComponent } from './components/home.component'; const routes: Routes = [ // Root { path: '/', name: 'Home', component: HomeComponent, useAsDefault: true}, ]; // - Updated Export export const routing = RouterModule.forRoot(routes);
... and the app.component.ts file:
import { Component, ViewContainerRef } from '@angular/core'; @Component({ selector: 'app', templateUrl: '/templates/app.component.html' }) export class AppComponent { viewContainerRef: any; public constructor(viewContainerRef:ViewContainerRef) {
Is there something I'm missing here?
javascript angularjs typescript routing
Emmanuel scarabin
source share