In angular 4 App, My typescript Model,
export class Person{
fname:string,
lname?:string
}
lname is optional. Fill the model like below in the component
//Query form data
var people = form.get('people');
let model = new Person(){
fname: people.get('firstname'),
lname: people.get('lastname')
}
At this scenario, if i try to convert my model to json, when user doesn't enter value for lastname. My json output will look like below,
{'fname': 'xyz', 'lname': null}
Expected Result:
But I want to eliminate all the null value properties in my json. So I am expecting
{'fname':'xyz'}
but when user enters value at lname. the json should like below
{'fname':'xyx', 'lname': 'abc'}
How can i produce this json result from typescript model