【发布时间】:2020-02-09 08:12:09
【问题描述】:
我是 Angular 的新手。所以我可能无法正确地提出问题。我提前道歉。我也试过this 问题。我为我的MEAN stack 应用程序创建了一个登录表单。这是一个使用email 和password 字段的简单登录。我的打字稿文件决定登录是否成功。这是我的代码。
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";
}
)
}
}
在上述文件中,flag 是一个布尔变量。 True 表示值正常,否则为 False。
这是我的 html 代码 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>
请多多关注我的span 标签。请纠正我。我得到了
“document.querySelector(...) 为空”
如您所见。 fa 图标在那里。但没有消息。
【问题讨论】:
标签: html angular typescript