相关疑难解决方法(0)

如何在Angular 6中的keyup事件中实现去抖时间

我创建了一个Angular应用程序,可以从API中搜索学生.它工作正常但每次更改输入值时都会调用API.我做过一项研究,我需要一些叫debounce的东西,但我不知道如何在我的应用程序中实现它.

App.component.html

    <div class="container">
  <h1 class="mt-5 mb-5 text-center">Student</h1>
<div class="form-group">
  <input  class="form-control form-control-lg" type="text" [(ngModel)]=q (keyup)=search() placeholder="Search student by id or firstname or lastname">
</div>
 <hr>
 <table class="table table-striped mt-5">
    <thead class="thead-dark">
      <tr>
        <th scope="col" class="text-center" style="width: 10%;">ID</th>
        <th scope="col" class="text-center" style="width: 30%;">Name</th>
       <th scope="col" style="width: 30%;">E-mail</th>
        <th scope="col" style="width: 30%;">Phone</th> 
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let result of results">
        <th scope="row">{{result.stu_id}}</th>
        <td>{{result.stu_fname}} {{result.stu_lname}}</td>
         <td>{{result.stu_email}}</td>
        <td>{{result.stu_phonenumber}}</td> 
      </tr>
    </tbody>
  </table>
</div>
Run Code Online (Sandbox Code Playgroud)

App.component.ts

import { Component} from '@angular/core';
import { Http,Response } from …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular

19
推荐指数
4
解决办法
2万
查看次数

标签 统计

angular ×1

rxjs ×1

typescript ×1