错误 错误:没有路由器的提供程序!在注入错误 (core.es5.js:1231) [角度]



我收到此错误。我的 angularJS 2 应用程序现在很小。我是AngularJS的新手。请帮忙!提前谢谢你。 app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MaterialModule } from '@angular/material';

dashboard.module.ts

import { ToolbarMultirow } from './toolbar-multirow';
import { DashboardComponent } from './dashboard/dashboard.component';
import { DashboardService } from './dashboard/shared/dashboard.service';
import { DashboardModule } from './dashboard/dashboard.module';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
HttpModule,
ReactiveFormsModule,
MaterialModule,
DashboardModule
],
declarations: [
ToolbarMultirow,
// DashboardComponent
],
providers: [
DashboardService
],
bootstrap: [
ToolbarMultirow,
DashboardComponent
],
})
export class AppModule { }
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { DashboardComponent } from './dashboard.component';
import { DashboardService } from './shared/dashboard.service';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpModule
],
declarations: [
DashboardComponent
],
exports: [
DashboardComponent,
CommonModule,
FormsModule
],
providers: [
// DashboardService
],
bootstrap: [
// DashboardComponent
]
})
export class DashboardModule { }

DashboardComponent_Host.html:1 错误上下文DebugContext_ {查看: Object, nodeIndex: 1, nodeDef: Object, elDef: Object, elView: Object} View_DashboardComponent_Host_0 @ DashboardComponent_Host.html:1 proxyClass @ compiler.es5.js:13572 DebugContext_.logError @ core.es5.js:12953 ErrorHandler.handleError @ core.es5.js:1149 (匿名) @ core.es5.js:4660 ZoneDelegate.invoke @ zone.js:365 onInvoke @ core.es5.js:4125 ZoneDelegate.invoke @ zone.js:364 Zone.run @ zone.js:125 (anonymous) @ zone.js:760 ZoneDelegate.invokeTask @ zone.js:398 onInvokeTask @ core.es5.js:4116 ZoneDelegate.invokeTask @ zone.js:397 Zone.runTask @ zone.js:165 drainMicroTaskQueue @ 区域.js:593 区域.js:569 未处理的承诺拒绝:没有提供程序 路由器!;区:;任务:承诺;值:错误:否 路由器提供商! 在注入错误 (core.es5.js:1231) [角度] at noProviderError (core.es5.js:1269) [angular] 在ReflectiveInjector_。throwOrNull (core.es5.js:2770) [角度] 在反射喷油器。getByKeyDefault (core.es5.js:2809) [角度] 在反射喷油器。getByKey (core.es5.js:2741) [角度] at ReflectiveInjector.get(core.es5.js:2610) [角度] at AppModuleInjector.NgModuleInjector.get (core.es5.js:3557) [angular] at resolveDep (core.es5.js:10930) [角度] at createClass (core.es5.js:10799) [angular] at createDirectiveInstance (core.es5.js:10627) [angular] at createViewNodes (core.es5.js:11977) [angular] at createRootView (core.es5.js:11882) [angular] at callWithDebugContext (core.es5.js:13013) [angular] at Object.debugCreateRootView [as createRootView] (core.es5.js:12474) [angular] error 注射时错误 (http://localhost:4200/vendor.bundle.js:2025:86) [角度] at noProviderError (http://localhost:4200/vendor.bundle.js:2063:12) [角度] 在ReflectiveInjector_。投掷或空 (http://localhost:4200/vendor.bundle.js:3564:19) [角度] 在反射喷油器。getByKeyDefault (http://localhost:4200/vendor.bundle.js:3603:25) [角度] 在反射喷油器。getByKey (http://localhost:4200/vendor.bundle.js:3535:25) [角度] at ReflectiveInjector.get(http://localhost:4200/vendor.bundle.js:3404:21) [角度] at AppModuleInjector.NgModuleInjector.get (http://localhost:4200/vendor.bundle.js:4351:52) [angular] 在分辨率 (http://localhost:4200/vendor.bundle.js:11724:45) [角度] at createClass (http://localhost:4200/vendor.bundle.js:11593:32) [Angular] at createDirectiveInstance (http://localhost:4200/vendor.bundle.js:11421:37) [angular] at createViewNodes (http://localhost:4200/vendor.bundle.js:12771:49) [Angular] at createRootView (http://localhost:4200/vendor.bundle.js:12676:5) [angular] at callWithDebugContext (http://localhost:4200/vendor.bundle.js:13807:42) [angular] at Object.debugCreateRootView [as createRootView] (http://localhost:4200/vendor.bundle.js:13268:12) [angular] 控制台错误 @ 区域.js:569 句柄未处理拒绝 @ 区域.js:574 _loop_1 @ zone.js:609 drainMicroTaskQueue @ zone.js:613 zone.js:571 错误:未捕获(承诺中):错误:路由器没有提供程序!错误 在注入错误 (core.es5.js:1231) [角度] at noProviderError (core.es5.js:1269) [angular] 在ReflectiveInjector_。throwOrNull (core.es5.js:2770) [角度] 在反射喷油器。getByKeyDefault (core.es5.js:2809) [角度] 在反射喷油器。getByKey (core.es5.js:2741) [角度] at ReflectiveInjector.get(core.es5.js:2610) [角度] at AppModuleInjector.NgModuleInjector.get (core.es5.js:3557) [angular] at resolveDep (core.es5.js:10930) [角度] at createClass (core.es5.js:10799) [angular] at createDirectiveInstance (core.es5.js:10627) [angular] at createViewNodes (core.es5.js:11977) [angular] at createRootView (core.es5.js:11882) [angular] at callWithDebugContext (core.es5.js:13013) [angular] at Object.debugCreateRootView [as createRootView] (core.es5.js:12474) [angular] 在注入错误 (core.es5.js:1231) [角度] at noProviderError (core.es5.js:1269) [angular] 在ReflectiveInjector_。throwOrNull (core.es5.js:2770) [角度] 在反射喷油器。getByKeyDefault (core.es5.js:2809) [角度] 在反射喷油器。getByKey (core.es5.js:2741) [角度] at ReflectiveInjector.get(core.es5.js:2610) [角度] at AppModuleInjector.NgModuleInjector.get (core.es5.js:3557) [angular] at resolveDep (core.es5.js:10930) [角度] at createClass (core.es5.js:10799) [angular] at createDirectiveInstance (core.es5.js:10627) [angular] at createViewNodes (core.es5.js:11977) [angular] at createRootView (core.es5.js:11882) [angular]at callWithDebugContext (core.es5.js:13013) [angular] at Object.debugCreateRootView [as createRootView] (core.es5.js:12474) [angular] 在 resolvePromise (zone.js:712) [] 在 :4200/polyfills.bundle.js:3326:17 [] 在 :4200/polyfills.bundle.js:3342:33 [] at Zone.run (zone.js:125) [ => ] 在 :4200/polyfills.bundle.js:3448:57 [] at Zone.runTask (zone.js:165) [ => ] at drainMicroTaskQueue (zone.js:593) [] consoleError @ zone.js:571 handleUnhandledRejection @ zone.js:574 _loop_1 @ zone.js:609 drainMicroTaskQueue @ zone.js:613

只需将路由器模块添加到导入中即可。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { DashboardComponent } from './dashboard.component';
import { DashboardService } from './shared/dashboard.service';
@NgModule({
imports: [
RouterModule, <-------
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpModule
],
declarations: [
DashboardComponent
],
exports: [
DashboardComponent,
CommonModule,
FormsModule
],
providers: [
// DashboardService
],
bootstrap: [
// DashboardComponent
]
})
export class DashboardModule { }

相关内容

最新更新