a simple login app, where I have a username and password:
The problem is even though my credentials are correct the program gives me a false output, is there any way to fix this?
.HTML
<label>Username</label>
<input type="text" [id]="uname">
<br>
<label>Password</label>
<input type="password" [id]="pass">
<br>
<button (click)="loginUser()"> Sign In</button>
.TS
loginUser(){
if(this.uname == "admin" && this.pass == "admin"){
alert('Login')
}else{
alert('Invalid')
}
}
The output gives me 'Invalid' which falls in the else how can I make it as true?
CodePudding user response:
Change [id] to [(ngModel)]. Gives you more control and, well, works.
CodePudding user response:
I don't know how you are fetching the [id]=uname with the this.uname but perhaps your not doing it at all and that's why it's saying "Invalid".
Try doing it with [(ngModel)] - it will fetch your uname with this.uname or even better- try using reactive forms.
