Could someone help me understand the error message I'm getting in my code below? The error says "Property 'json' does not exist on type 'User'". Here are some details about my setup:
Angular version: 12.2.12 Node: 16.13.0 Package Manager: npm 8.1.2
// model.ts
export class User{
UserID : number
UserName : string
FirstName : string
LastName : string
Email : string
Password : string
ConfrimPass : string
UserRole : string
Authorize_building :string
}
//component.ts
resetForm(form? : NgForm) {
if (form != null)
form.reset();
this.userService.selectUser = {
UserID: null,
UserName: '',
FirstName: '',
LastName: '',
Email: '',
Password: '',
ConfrimPass: '',
UserRole: '',
Authorize_building: '',
}
}
//service.ts
PostUser(usr : User): Observable<User>{
var body = JSON.stringify(usr);
var headerOption = new Headers({ 'Content-Type' : 'application/json' });
var requestOption = new RequestOPtions({ method: RequestMethod.Post, headers: headerOption });
// return this.http.post('https://localhost:44339/api/Users', body, requestOption).map(x => x.json());
var headersOption = ({ 'Content-Type' : 'application/json' });
var body = JSON.stringify(usr);
return this.http.post<User>('https://localhost:44339/api/Users', body, { headers: headersOption } ).map(x => x.json());
};
}
Please provide a solution to resolve this issue!