简体   繁体   English

角度无法分配给“名称”,因为它是常量或只读属性

[英]Angular Cannot assign to 'name' because it is a constant or a read-only property

Im getting error Cannot assign to 'name' because it is a constant or a read-only property. 即时消息错误无法分配给“名称”,因为它是常量或只读属性。 When send data to api. 将数据发送到api时。 Any one know how can i solve this ? 有人知道我该如何解决? Thanks 谢谢

  onSubmit() {
  name = this.backUrl || 'admin';
  console.log(name);
    const formData = new FormData();

    formData.append('avatar', this.form.get('avatar').value);
    formData.append('name', name);


    this.uploadService.uploadFile(formData).subscribe(
      (res) => {
        this.uploadResponse = res;
          console.log(res);
      },
      (err) => {  
        console.log(err);
      }
    );
  }

您需要将name声明为letvar才能为其分配值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度2 | 无法分配给数组,因为它是常量或只读属性 - Angular 2 | cannot assign to array because it is a constant or a read-only property 角度2 | 无法分配给变量,因为它是常量或只读属性 - Angular 2 | cannot assign to variable because it is a constant or a read-only property 无法分配给“total”,因为它是一个常量或只读属性 - Cannot assign to 'total' because it is a constant or a read-only property 获取错误:'无法分配到'location',因为它是一个常量或只读属性'与Angular app中的mailto函数 - Getting error: 'Cannot assign to 'location' because it is a constant or a read-only property' with mailto function in Angular app 无法分配给“值”,因为它是常量或只读属性。 Angular 6 - Cannot assign to 'value' because it is a constant or a read-only property. Angular 6 无法分配给“地理位置”,因为它是只读属性(有角度的 Jest) - Cannot assign to 'geolocation' because it is a read-only property (angular Jest) 错误 TS2540:无法分配给“i”,因为它是常量或只读属性 - error TS2540: Cannot assign to 'i' because it is a constant or a read-only property “无法分配给 var,因为它是只读属性。” 使用 Jasmine 测试框架进行角度测试 - "Cannot assign to var because it is a read-only property." in angular test using Jasmine Test Framework TS2540:无法分配给“矩阵”,因为它是只读属性 - TS2540: Cannot assign to 'matricule' because it is a read-only property 错误 TS2540:无法分配给“vfs”,因为它是只读属性 - error TS2540: Cannot assign to 'vfs' because it is a read-only property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM