当我尝试提供角度应用程序时,我收到以下错误
zone.js:642未处理的承诺拒绝:没有ErrorHandler。是平台 包含模块(BrowserModule)? ;区域:;任务:Promise.then; 值:错误:没有ErrorHandler。是平台模块(BrowserModule) 包括?
但在我的app.module中我有
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {LocationStrategy, HashLocationStrategy} from '@angular/common';
import {AppComponent} from './app.component';
import {BsDropdownModule} from 'ngx-bootstrap/dropdown';
import {TabsModule} from 'ngx-bootstrap/tabs';
import {NAV_DROPDOWN_DIRECTIVES} from './shared/nav-dropdown.directive';
import {ChartsModule} from 'ng2-charts/ng2-charts';
import {SIDEBAR_TOGGLE_DIRECTIVES} from './shared/sidebar.directive';
import {AsideToggleDirective} from './shared/aside.directive';
import {BreadcrumbsComponent} from './shared/breadcrumb.component';
// Routing Module
import {AppRoutingModule} from './app.routing';
// Firebase
import {AngularFireModule} from 'angularfire2';
import {AngularFireAuthModule} from 'angularfire2/auth';
import {AngularFireDatabase} from 'angularfire2/database';
// Layouts
import {FullLayoutComponent} from './layouts/full-layout.component';
import {environment} from '../environments/environment';
import {SimpleLayoutComponent} from './layouts/simple-layout.component';
import {AuthService} from './auth/auth.service';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatSliderModule} from '@angular/material/slider';
import {MatTooltipModule} from '@angular/material/tooltip';
import {DragulaModule, DragulaService} from 'ng2-dragula';
import {HttpModule} from '@angular/http';
import {AdminGuard} from './admin-guard.service';
@NgModule({
exports: [
MatSliderModule,
MatTooltipModule,
]
})
@NgModule({
imports: [
FormsModule,
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatTooltipModule,
MatSliderModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
ChartsModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireAuthModule,
HttpModule,
],
declarations: [
AppComponent,
FullLayoutComponent,
SimpleLayoutComponent,
NAV_DROPDOWN_DIRECTIVES,
BreadcrumbsComponent,
SIDEBAR_TOGGLE_DIRECTIVES,
AsideToggleDirective,
],
providers: [{
provide: LocationStrategy,
useClass: HashLocationStrategy
},
AngularFireDatabase,
AuthService,
DragulaService,
AdminGuard,
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
在使用Angular 4.1.3之前不会出现此错误,但是当我升级到Angular 5.2时,我在浏览器的控制台中出现此错误。我不确定是不是因为我遗漏了这个文件中的内容,或者当我更新某些内容时导致错误。
导致此错误的原因是什么?
答案 0 :(得分:0)
为什么在一个类上有两个@ngModule
装饰器
如果在同一个类上使用两个装饰器,则两个装饰器将以相反的顺序应用于类并在该类上存储元数据,以便第一个装饰器属性存储在最后一个索引中。当编译器解析元数据时,它使用findLast函数获取最后的元数据属性,该函数基本上选择文件中的第一个装饰器属性。
简而言之,只使用了第一个装饰器。More here
修改你的app模块放置exports
数组,如下所述,这将解决问题。 Docs
@NgModule({
exports: [
MatSliderModule,
MatTooltipModule,
],
imports: [
FormsModule,
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatTooltipModule,
MatSliderModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
ChartsModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireAuthModule,
HttpModule,
],
declarations: [
AppComponent,
FullLayoutComponent,
SimpleLayoutComponent,
NAV_DROPDOWN_DIRECTIVES,
BreadcrumbsComponent,
SIDEBAR_TOGGLE_DIRECTIVES,
AsideToggleDirective,
],
providers: [{
provide: LocationStrategy,
useClass: HashLocationStrategy
},
AngularFireDatabase,
AuthService,
DragulaService,
AdminGuard,
],
bootstrap: [ AppComponent ]
})