ibeautiful
只有一种情况,如果你需要进行AOT编译,你必须避免使用箭头功能,如此处所述配置模块时,不能使用箭头功能。❌DONT:import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { Routes, RouterModule } from '@angular/router';@NgModule({
imports: [
BrowserModule,
RouterModule,
HttpModule,
RouterModule.forRoot([], { errorHandler: (err) => console.error(err) })
],
bootstrap: [
AppComponent
],
declarations: [
AppComponent
]})export class AppModule {}✅做:import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { Routes, RouterModule } from '@angular/router';function errorHandler(err) {
console.error(err);}@NgModule({
imports: [
BrowserModule,
RouterModule,
HttpModule,
RouterModule.forRoot([], { errorHandler })
],
bootstrap: [
AppComponent
],
declarations: [
AppComponent
]})export class AppModule {}