【发布时间】:2018-06-10 06:09:27
【问题描述】:
我想在标志变量为真时显示加载器,在标志为假时隐藏它(双向数据绑定),但我不知道如何将 *ngIf 与组件变量一起使用
app.component.ts
import { Component, OnInit } from '@angular/core';
import { User } from '../../models/users.model';
import { UserServices } from '../../services/User.service';
@Component({
selector: 'app-default',
templateUrl: './default.component.html',
styleUrls: ['./default.component.css']
})
export class defaultComponent implements OnInit {
public flag: boolean;
userList: User[];
constructor(private _service: UserServices) {
this.flag = true;
}
ngOnInit() {
this.getData();
}
getData() {
this.flag = true;
this._service.loadData().subscribe( response => { this.userList = response; });
this.flag = false;
}
}
default.component.html
<div *ngIf="flag == true" class="loader">Loading...</div>
<div class="content">
<!--my html-->
</div>
我只想在调用服务时显示加载器 div,并在调用完成后隐藏它。
【问题讨论】:
-
你有什么问题?
-
我只想在调用服务时显示加载器,并在调用完成后隐藏它。
-
你的
loader类风格中是否有类似display:none;的东西?如果是这样,请删除该行。
标签: angular angular-components