Issue
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;```
Solution
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 }));
Answered By - Yong Shun
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.