相关疑难解决方法(0)

TS2531:对象可能是'null'

我有以下功能: -

uploadPhoto() {
    var nativeElement: HTMLInputElement = this.fileInput.nativeElement;

    this.photoService.upload(this.vehicleId, nativeElement.files[0])
        .subscribe(x => console.log(x));
}
Run Code Online (Sandbox Code Playgroud)

但是在nativeElement.files [0]上,我收到了一个打字稿错误,"对象可能是'null'".有人可以帮我解决这个问题吗?

我试图将nativeElement声明为null值,但是没有成功.

谢谢你的帮助和时间.

typescript angular

12
推荐指数
4
解决办法
9830
查看次数

标签 统计

angular ×1

typescript ×1