登录凭据错误时,我无法显示警告消息。它不显示在else范围内,但是当我在if范围中输入消息时,它会显示?有人能帮我吗?
message:string;
//login user credentials to authenticate
submitForm() {
this.service.login(this.login.username, this.login.password)
.subscribe(data => {
if(data == true){
}else {
this.message = "Username or Password Invalid";
}
});
}
// HTML
<div *ngIf="message" class="alert alert-danger text-center " style="width: 40%; font-size: 16px" >{{message}}</div>
答案 0 :(得分:0)
您必须更改作业:
if (data === true) is the solution
更好的解决方案是
if ( data )
答案 1 :(得分:0)
试试这个
message:string;
submitForm() {
this.service.login(this.login.username, this.login.password)
.subscribe(data => {
if(!data){
this.message = "Username or Password Invalid";
}
});
}