自从升级到angular 9以来,我们不断收到无法使用* ngIf的错误。
它只抱怨运行时间。没有构建错误。
我们大约有10个延迟加载的模块。
主模块具有BrowserModule的导入。
所有子模块都具有CommonModule的导入。
如果我们使用ng serve --prod运行它,它将起作用。但只是简单地服务就会拒绝。
这使开发工作变得很麻烦,因为每次更改后需要更长的时间进行编译。
我们得到的错误是:无法绑定到'* ngIf',因为它不是'div'的已知属性。
<div class="m-grid__item m-grid__item--fluid m-grid__item--order-tablet-and-mobile-1 m-login__wrapper" *ngIf="dataLoaded">
这就是它的抱怨。 我们还使用Angular 9.0.5以及所有其他最新版本的库。
我们懒于通过路由加载模块。
path: 'login',
loadChildren: () => import('./unauthenticated/auth.module').then(m => m.AuthModule),
请不要将其标记为重复项,因为我已经尝试了互联网上的每件事,但是似乎没有任何作用。
这是tsconfig的设置值。
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
应用模块导入
imports: [
HttpClientModule,
BrowserModule,
BrowserAnimationsModule,
CommonModule,
OverlayModule,
AppRoutingModule,
LayoutModule,
TranslateModule.forRoot(),
NotificationModule
],
这是auth模块,它是受影响的模块之一。
当前方案适用于AuthComponent。
问题出在所有模块上。
imports: [
CommonModule,
NotificationModule,
TranslateModule.forChild(),
RouterModule.forChild([
{
path: '',
component: AuthComponent
}
]),
SharedModule,
CoreModule
],
providers: [AuthClient, GlobalClient, NotificationHelperService, DealerClient, UserClient, AuthenticationService, SignalRService],
declarations: [
AuthComponent,
LoginComponent,
ForgotPasswordComponent,
AuthNoticeComponent,
EulaComponent,
ActivateAccountComponent,
ResetPasswordComponent,
LoginTwoFactorAuthenticationComponent,
BaseAuthComponent,
ChangeEmailComponent,
DealersNotFoundComponent,
SystemOfflineComponent,
DealersSuspendedComponent
]
答案 0 :(得分:1)
您的主模块应具有 从'@ angular / common'导入{CommonModule};