【发布时间】:2020-05-08 09:43:27
【问题描述】:
由于一段时间以来,类型检查在 VSCode 中的 Angular 模板中不起作用。
我有以下代码:
<div *ngIf="activeProperty" class="mx-3">
<!-- some other code -->
<input
required
id="propertyName"
type="text"
class="form-control"
name="propertyName"
[ngModel]="activeProperty.uiProperty.label"
(ngModelChange)="updateLabelAndKeyInSpec($event)"
/>
</div>
现在在这一行:
[ngModel]="activeProperty.uiProperty.label"
activeProperty 带有下划线,告诉我The expression might be null 这显然是错误的,因为我正在通过上面的*ngIf 进行检查。
请在此处查看我的ng --version:
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 8.3.6
Node: 12.7.0
OS: win32 x64
Angular: 8.2.8
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.6
@angular-devkit/build-angular 0.803.6
@angular-devkit/build-optimizer 0.803.6
@angular-devkit/build-webpack 0.803.6
@angular-devkit/core 8.3.6
@angular-devkit/schematics 8.3.6
@angular/cdk 8.2.2
@angular/cli 8.3.6
@angular/http 7.2.15
@ngtools/webpack 8.3.6
@schematics/angular 8.3.6
@schematics/update 0.803.6
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2
我做错了吗?
【问题讨论】:
-
表达式可能为空 - 你从哪里得到这个错误?
-
VS Code 在抱怨,所以我认为这是
tslint错误 -
[ngModel]="activeProperty?.uiProperty?.label" 你可以试试这个方法吗。
-
@hrdkisback 谢谢,但我以前读过这个。如您所见,
*ngIf并没有解决我的问题。
标签: html angular typescript tslint