gpt4 book ai didi

angular2 路由类型错误 : Cannot read property 'forRoot'

转载 作者:太空狗 更新时间:2023-10-29 17:37:17 24 4
gpt4 key购买 nike

angular2 rc.5

我收到 TypeError: Cannot read property 'forRoot' of undefined(...)当我调查时,我发现 RouterModule 在执行期间是 undefined

以下是我的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

以下是我的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 { }

和 main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
//import { HTTP_PROVIDERS } from '@angular/http';
import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

最佳答案

我遇到了同样的问题。也许这很老套,但就我而言,清除浏览器缓存后问题就解决了。

关于angular2 路由类型错误 : Cannot read property 'forRoot' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38903428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com