I'm new to Angular. So I may not be able to frame the question correctly. I apologize in advance. I have also tried this question. I have created a login form for my MEAN stack
application. Its a simple login with email
and password
field. My typescript file decides whether the login was successful or not. Here is my code.
login.component.ts
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../auth.service';
...
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
flag= {
valid: true
}
...
constructor( private _auth: AuthService, private _router: Router) {
}
ngOnInit() {
}
onSubmit() {
this._auth.loginUser(this.loginUserData)
.subscribe(
res => {
...
},
err => {
this.flag.valid=false,
document.querySelector('#login-denied').innerHTML="hello";
}
)
}
}
In the above file, flag
is a boolean variable. True means values are OK and False otherwise.
Here is my html code login.component.html
<form>
<div class="form-group">
USERNAME FIELD
</div>
<div class="form-group">
PASSWORD FIELD
</div>
<button type="submit" (click)="onSubmit()">Submit</button>
<span *ngIf="flag.valid===false" id="login-denied">
<i class="fa fa-times-circle" style="color:firebrick;"></i>
</span>
</form>
Please pay more attention to my span
tag. Please correct me. I am getting
"document.querySelector(...) is null"
As you can see. The fa
icon is there. But no message.