0
I’m using ngModel to insert value into variable through input, but the same is not being recognized, if I do with isolated values it returns nothing, if I try with object it returns Undefined
Html template:
<form class="form-signin">
<div class="form-label-group">
<h2>Login do Usuário</h2>
</div>
<div class="form-label-group">
<input type="email" id="emailLogin" class="form-control" placeholder="Digite seu e-mail" [(ngModel)]="usuario"/>
</div>
<div class="form-label-group">
<input type="password" id="senhaLogin" class="form-control" placeholder="Digite sua senha" [(ngModel)]="senha"/>
</div>
<div class="form-label-group">
<button class="btn btn-lg btn-primary btn-block" type="submit" (click)="loginUsuario()" >Entrar</button>
</div>
</form>
Component.:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-login-usuario-page',
templateUrl: './login-usuario-page.component.html',
styleUrls: ['./login-usuario-page.component.css'],
})
export class LoginUsuarioPageComponent implements OnInit {
public usuario = "";
public senha = "";
constructor() {
}
ngOnInit() {
}
loginUsuario() : void{
alert(this.usuario + " - " + this.senha);
}
}
Check that you are importing the formsModule in the module that you leave this component
– Eduardo Vargas
@Eduardovargas It was an attribute in the input tag that was missing, in my case it was the name attribute. formsModule was already declared yes, in the main application component, and it was there that I declared my component.
– FelipeDwD