I use FormBuilder to generate an object and send it to an API, but the generated object is not quite the format that the API expects. I need to know how to add objects inside objects using FormBuild. I did a "gambiarra" to work, but wanted to know how to do it more professionally.
createForm(create) {
this.formRegister = this.formBuilder.group({
nome: [create.nome, [ Validators.required ]],
email: [create.email, [ Validators.required, Validators.email ]],
celular: [create.celular, [ Validators.required ]],
cpf: [create.cpf, [ Validators.required ]],
senha: [create.senha, [ Validators.required ]],
sexo: [create.sexo, [ Validators.required ]],
dataNascimento: [create.dataNascimento, [ Validators.required ]]
});
}
I was using this function to wrap my object
objTransf() {
let data = new PreCadastro;
data = {
'pessoa': {
'nome': this.formRegister.value.nome,
'email': this.formRegister.value.email,
'cpf': this.formRegister.value.cpf,
'sexo': this.formRegister.value.sexo,
'dataNascimento': this.formRegister.value.dataNascimento,
'contato': {
'celular': this.formRegister.value.celular
}
},
'usuario': {
'login': this.formRegister.value.email,
'senha': this.formRegister.value.senha
},
'preCadastro': true
};
this.addElement(data);
}
If you have a link from a story or example, it would be a great help.