【发布时间】:2020-05-29 14:32:45
【问题描述】:
我有这个用于上传文档的输入,我正在尝试检查它是否为空以显示警报。
这是我的代码:
<div class="form-group">
<input type="file" name="file" accept="application/pdf, application/msword, application/vnd.ms-powerpoint"
(change)="onUpload($event)">
<input type="text" #documentLink class="form-control" name="urlDocument" [value]="urlDocument | async">
</div>
<div *ngIf="!documentLink.value" class="alert alert-danger">
Imaginea de coperta este necesara!
</div>
我有这个错误:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
Previous value: 'ngIf: true'. Current value: 'ngIf: false'.
我用这个viewchild取值
@ViewChild('documentLink', {static: false}) inputDocumentLink : ElementRef;
这就是我在数据库中添加它的方法:
const link = this.inputDocumentLink.nativeElement.value;
...
你能帮帮我吗?非常感谢!
【问题讨论】:
-
你在哪里设置 documentLink?
-
我的 ts 中有这样的东西:@ViewChild('documentLink', {static: false}) inputDocumentLink : ElementRef;
-
我在我的方法中采用这样的值: const link = this.inputDocumentLink.nativeElement.value;
-
可以把你的ts文件放在上面吗?
-
@Aakash Garg - 据我所知,
#documentLink已在模板中设置。
标签: angular error-handling upload checked