angular2 rc.5
I am getting TypeError: Cannot read property 'forRoot' of undefined(…)
when i investigated i found that RouterModule
is undefined
during execution.
Following is my app.route.ts
import {Routes, RouterModule } from '@angular/router';
//const routes: Routes = [];
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
import {AdditionComponent} from './addition.component';
import {RomanComponent} from './roman.component';
let routes: Routes = [
{
path: 'hello',
component: HelloComponent
},
{
path: '',
redirectTo: '/hello',
pathMatch: 'full'
},
{
path: 'increment',
component: IncComponent
},{
path: 'adder',
component: AdditionComponent
},{
path: 'roman',
component: RomanComponent
}
];
export const routing = RouterModule.forRoot(routes); // error on this line
Following is my app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {routing} from './app.routes';
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
import {AdditionComponent} from './addition.component';
import {RomanComponent} from './roman.component';
@NgModule({
imports:[
BrowserModule,
routing
],
declarations: [
AppComponent,
HelloComponent,
IncComponent,
AdditionComponent,
RomanComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
and main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
//import { HTTP_PROVIDERS } from '@angular/http';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
I had the same problem. Maybe it's corny, but in my case, problem was solved after I cleared the browser cache.
I had this same issue working in a .NET Core web application in Visual Studio 2015. I upgraded my packages from rc4 to rc5, did an npm install
and saw this error after I refreshed my browser. I eventually realized that I forgot to copy the updated packages from node_modules to my lib folder inside wwwroot (I have a gulp task that does this). After running the task to update the libs everything was back to normal. Hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With