Javascript 如何在加载物料表时显示加载微调器
嗨,我正在使用angular来显示一个表。我使用了material table,为了在加载表格时显示微调器,我定义了一个变量isLoading。它的工作原理如下: 在ts文件中:Javascript 如何在加载物料表时显示加载微调器,javascript,html,angular,Javascript,Html,Angular,嗨,我正在使用angular来显示一个表。我使用了material table,为了在加载表格时显示微调器,我定义了一个变量isLoading。它的工作原理如下: 在ts文件中: @Component({ selector: 'app-dashboard', templateUrl: './dashboard.component.html', styleUrls: ['./dashboard.component.scss'] }) export class DashboardCom
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit{
dataSource = new MatTableDataSource<Ticket>();
isLoading = true;
constructor(private ticket: TicketService,
ngOnInit() {
this.getAllTicket();
}
getAllTicket() {
this.ticket.getAllTicket(queryParams).then((res: Ticket[]) => {
this.isLoading = false;
this.ticketList = res;
this.originalTicketList = this.ticketList;
this.dataSource.data = this.ticketList;
});
}
searchTicket() {
this.getAllTicket();
}
}
@组成部分({
选择器:“应用程序仪表板”,
templateUrl:“./dashboard.component.html”,
样式URL:['./dashboard.component.scss']
})
导出类DashboardComponent实现OnInit{
dataSource=新MatTableDataSource();
isLoading=true;
建造商(私人票:票务服务、,
恩戈尼尼特(){
这个.getAllTicket();
}
getAllTicket(){
this.ticket.getAllTicket(queryParams)。然后((res:ticket[])=>{
this.isLoading=false;
this.ticketList=res;
this.originalTicketList=this.ticketList;
this.dataSource.data=this.ticketList;
});
}
搜索票证(){
这个.getAllTicket();
}
}
我的html是这样的:
<div id="main-body">
<div class="search-bar">
<select [(ngModel)]="searchBy" class="border-primary">
<option value="">-- choose an option--</option>
<option value="id">SIR ID</option>
</select>
<!-- here is the input i type and hit enter to trigger searchTicket() function -->
<input type="text" class="form-control card border-primary ele fnt"
placeholder="Enter the SIR ID or Host or sha256 or User ID" aria-label="Ticket Id"
aria-describedby="button-addon2" [(ngModel)]="currentTicketId" (keyup.enter) = "searchTicket()">
</div>
</div>
<div class="ticket-result">
<div class="ticket-container">
<table mat-table matTableExporter [dataSource]="dataSource" matSort class="mat-elevation-z8">
<!-- my table column definition here -->
</table>
<mat-card *ngIf="isLoading" class="mat-card-style">
<mat-progress-spinner color="primary" mode="indeterminate">
</mat-progress-spinner>
</mat-card>
</div>
</div>
</div>
--选择一个选项--
先生身份证
因此,我定义了一个isLoading变量,当加载数据时,会显示加载微调器。但这只发生在加载页面时。在我的html中有一个输入字段,键入某个内容并点击enter,然后触发searchTicket()函数。此函数还用于从getAllTicket()检索数据功能
此时isLoading已为false,微调器将显示。因此,在触发此searchTicket()函数时,如何让微调器也显示
我试图在searchTicket()函数中添加
isLoading=true
,但这不起作用。只需将其设置回true即可
searchTicket() {
this.isLoading = true;
this.getAllTicket();
}
对不起,我还是没明白。你是说用getter和setter可以触发ngonchange吗