Home > Blockchain >  Property 'append' does not exist on type 'User'
Property 'append' does not exist on type 'User'

Time:10-04

here i've created 'user.model.ts'

  export class User {
  
  id: string;
  accountCode: string;
  picture: File;
  firstName: string;
  lastName: string;
  companyName: string;
  email: string;
  phone: string;
  password: string;
  parentId: string;
  gmailId:string;
  role: Role;
  customize: Customize;
  account: Account;
  
  constructor() {
    this.role = new Role();
    this.account = new Account();
    this.customize = new Customize();
  }
}

this is my 'signup.component.ts'. this file throws an error that "Property 'append' does not exist on type 'User'"

  let formData = new User();

      formData.account = this.user.account;
      formData.append('picture', this.signupForm.get('picture').value)
      formData.append('firstName', this.signupForm.get('firstName').value)
      formData.append('lastName', this.signupForm.get('lastName').value)
      formData.append('email', this.signupForm.get('email').value)
      formData.append('password', this.signupForm.get('password').value)
      formData.append('phone', this.signupForm.get('phone').value)
      formData.append('companyName', this.signupForm.get('companyName').value)
      formData.parentId = this.user.parentId;
      formData.role.id = constants.roleId;```

CodePudding user response:

You are mixed up the FormData and User.

The formData should be FormData instance but not User instance.

And append the data to FormData as below:

let formData = new FormData();

formData.append('account', JSON.stringify(this.user.account));
formData.append('picture', this.signupForm.get('picture').value);
formData.append('firstName', this.signupForm.get('firstName').value);
formData.append('lastName', this.signupForm.get('lastName').value);
formData.append('email', this.signupForm.get('email').value);
formData.append('password', this.signupForm.get('password').value);
formData.append('phone', this.signupForm.get('phone').value);
formData.append('companyName', this.signupForm.get('companyName').value);
formData.append('parentId', this.user.parentId);
formData.append('role', JSON.stringify({ id: constants.roleId }));
  • Related