gpt4 book ai didi

ModuleWithProviders 的 Angular 2 路由错误

转载 作者:太空狗 更新时间:2023-10-29 18:05:20 27 4
gpt4 key购买 nike

enter image description here

我是 Angular 2 的新手,我需要路由部分的帮助。我正在使用 http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial

我遇到了一个错误

Exported variable 'routing' has or is using name 'ModuleWithProviders' from external module "/home/frank/angular/node_modules/@angular/core/src/metadata/ng_module" but cannot be named.

这是我的代码

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

// used to create fake backend
import { fakeBackendProvider } from './_helpers/index';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { BaseRequestOptions } from '@angular/http';

import { AppComponent } from './app.component';
import { routing } from './app.routing';

import { AlertComponent } from './_directives/index';
import { AuthGuard } from './_guards/index';
import { AlertService, AuthenticationService, UserService } from './_services/index';
import { HomeComponent } from './home/index';
import { LoginComponent } from './login/index';
import { RegisterComponent } from './register/index';

@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
declarations: [
AppComponent,
AlertComponent,
HomeComponent,
LoginComponent,
RegisterComponent
],
providers: [
AuthGuard,
AlertService,
AuthenticationService,
UserService,

// providers used to create fake backend
fakeBackendProvider,
MockBackend,
BaseRequestOptions
],
bootstrap: [AppComponent]
})

export class AppModule { }

关于错误的任何想法?我还尝试了 seimport { ModuleWithProviders } from '@angular/core';tting my "declaration": true, in tsconfig.js and also imported

最佳答案

我通过这样做解决了这个问题:

export const routing: ModuleWithProviders = RouterModule.forRoot(APP_ROUTES);

并且不要忘记从@angular/core 导入 ModuleWithProviders

import { ModuleWithProviders } from "@angular/core";

关于ModuleWithProviders 的 Angular 2 路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41134288/

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