Reputation: 935
I have created an interface of User to put in some value from ngModel. Take a look at this.
user.ts
export class User{
_id: String;
username: String;
password: String;
firstname: String;
lastname: String;
gender: String;
address: String;
contact: Number;
email?: String;
}
Example of ngModel binding
<input type="text" [(ngModel)]="user.username" class="form-control" name="username" id="username" placeholder="Enter your Username" formControlName="username"/>
Output from the console log
I want to make the result to a json. I use JSON.parse but the error on the title pops up. How can I convert it to a json object? Thanks
Upvotes: 3
Views: 2729
Reputation: 13179
JSON.parse
is meant for creating a javascript object from a string (that is already formatted for JSON). What you're looking for is JSON.stringify
instead to convert your javascript object into JSON text.
Upvotes: 5