微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

希望我的搜索仅在单击按钮 angular 后显示

如何解决希望我的搜索仅在单击按钮 angular 后显示

我使用 angular 和 spring boot 来搜索 coli 使用 numeroColi 但我只希望我的结果在点击按钮后显示而不是在写作时显示,我也是希望我的结果在单击之前显示为空: 这是我的 app.component 函数

public searchColis(key: string): void{
    console.log(key);
    const results: Coli[] = [];
    for (const coli of this.colis){
      if (coli.numeroColi.toLowerCase().indexOf(key.toLowerCase()) !== -1) {
        results.push(coli);
      }
    }
    this.colis = results;
    if (results.length===0 || !key ){
      this.getColis();
    }
  }

这是我的 html 文件

 <div class="form-horizontal">
                <div class="form-group">
                    <label for="inputOrderTrackingID" class="col-sm-2 control-label">Order id</label>
                        <div class="col-sm-10">
                        <input type="text"  (ngModelChange)="searchColis(key.value)" ngModel #key="ngModel" name="key" class="form-control" id="inputOrderTrackingID" value="" placeholder="# put your order id here">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" id="shopGetorderStatusID" class="btn btn-success">Get status</button>
                    </div>
                </div>
            </div>
    
            <h4>Your order status:</h4>

            <ul  *ngFor="let coli of colis" class="list-group">
                <li class="list-group-item">
                    <span class="prefix">Description:</span>
                    <span class="label label-success">{{coli?.description}}</span>
                </li>
            </ul>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。