无法将图像高度和宽度分配给打字稿中的输入类型框

Can't assign image height and width to input type box in typescript

我正在尝试获取图像高度和图像宽度并将其分配给隐藏在 html 中的输入类型文本,如下所示:

目的是获取高度和宽度以检查和验证它​​们。

html:

<input type="file" class="file" #introIcon id="uploadBtn" (change)="onFileChange($event)" name="browseIcon">
<input type="number" class="hidden" id="imgWidth" value="">
<input type="number" class="hidden" id="imgHeight" value="">

ts:

onFileChange(event) {
      if (event.target.files.length > 0) {
        const file = event.target.files[0];
        this.fileName = file.name;
        this.fileType = file.type;
        if(this.fileType == 'image/png' || this.fileType == 'image/jpeg' || this.fileType == 'image/PNG' || this.fileType == 'image/JPEG') {
          const reader = new FileReader();
          reader.onload = e => {
            this.url = reader.result;
            var imageObj = new Image();
            imageObj.src = this.url;
            imageObj.onload = function () {
              console.log('p1:', imageObj.height);
              console.log('p2:', imageObj.width);
              // (<HTMLSelectElement>document.getElementById('imgWidth')).value = imageObj.width;  <-- here getting error
              // (<HTMLSelectElement>document.getElementById('imgHeight')).value = imageObj.height; <-- here getting error
            };
          }
          reader.readAsDataURL(file);
          let fName = (<HTMLSelectElement>document.getElementById('uploadFile')).value;
          fName = this.fileName;
          this.uploadFileName.nativeElement.value = fName;
          this.form.get('browseIcon').setValue(file);
        } else {
          // error
        }
      }
    }

在以下行中出现错误:

(<HTMLSelectElement>document.getElementById('imgWidth')).value = imageObj.width;  
(<HTMLSelectElement>document.getElementById('imgHeight')).value = imageObj.height;

Type 'number' is not assignable to type 'string'

我已经尝试了 google 但 none 的解决方案有效!

试过这个:

怎么样

(<HTMLSelectElement>document.getElementById('imgWidth')).value = imageObj.width.toString();  
(<HTMLSelectElement>document.getElementById('imgHeight')).value = imageObj.height.toString();