0
I have a class in Angular user call that gets 2 Boolean fields
export class UsuariosModel {
UsuarioId: Number;
Nome: string;
Sobrenome: string;
Email: string;
Senha: string;
Corretor: boolean;
Contrato: boolean;
}
On my page I have a form using formGroup and with all these fields, being the 'Broker' and the 'Contract' type:checkbox'. as follows...
<form [formGroup]="formUser" novalidate>
<label>Nome</label>
<input formControlName="nome" type="text" placeholder="Nome" />
<label>Sobrenome</label>
<input formControlName="sobrenome" type="text" placeholder="Sobrenome" />
<label>Email</label>
<input formControlName="email" type="text" placeholder="Email" />
<label>Senha</label>
<input formControlName="senha" type="text" placeholder="senha" />
<label>corretor</label>
<input formControlName="corretor" type="checkbox" />
<label>Contrato</label>
<input formControlName="contrato" type="checkbox" />
<button (click)="inserindoUsuario(formUser.value)">Criar</button>
</form>
In my Typescript of this page, I have a method that creates an object of type 'User' and receives the parameters of formGroup. But if I do not check the checkbox it comes empty this way 'contract:""', and not as false this way 'contract:false'...
Here is my Formgroup and my method...
Formgroup
constructor(fb: FormBuilder, private api: ChamadaApi, http: Http){
this.Http = http;
this.formUser = fb.group({
nome: new FormControl('', [Validators.required]),
sobrenome: new FormControl('', [Validators.required]),
email: new FormControl('', [Validators.required]),
senha: new FormControl('', [Validators.required]),
corretor: new FormControl(''),
contrato: new FormControl('', [Validators.required]),
});
}
Method
inserindoUsuario(usuarios: any){
this.usuariosModel = {
UsuarioId: null,
Nome: usuarios.nome,
Sobrenome: usuarios.sobrenome,
Email: usuarios.email,
Senha: usuarios.senha,
Corretor: usuarios.corretor,
Contrato: usuarios.contrato
}
this.api.CreateUser(this.usuariosModel);
}
Booooa, perfect, worked perfectly...
– Guilherme Nunes