错误TypeError:无法读取ng-autocomplete angular7中未定义的属性“名称”?

时间:2019-07-03 05:43:27

标签: autocomplete angular7

我已经在我们的网站中实现了自动完成功能,我已经正确使用了文档,但是在console.top中出现了错误。在搜索了任何我称为API的键之后,我在其中获得了数组结果但没有显示在html中。请检查以下代码是什么我的代码有误吗?

onChangeSearch(val) {
  this.searchUser = val;
    // do something when input is focused
    var lengthExist = this.searchUser.toString().length;
    if(lengthExist >= 3) {
       //pass the dataparam in the backend....
      var data = {
        "search_key" : this.searchUser,
        "user_id"    : this.loggedUserObject.user_id,
        "search_type" : "3"
      }

      this.filterList(data);
    }  else {
        //pass the dataparam in the backend....
        var data = {
          "search_key" : this.searchUser,
          "user_id"    : this.loggedUserObject.user_id,
          "search_type" : "3"
        }
        this.filterList(data);
    }
  }


  filterList(data  :any) {
    //st API URL here....
    var url =  '/api/common-search';

    //createUser function for create user in DB
    this.service.saveDetail(data, url).subscribe( (data : any) => {
      if(data.status) {
        this.data = data.result;
      } else {
        this.data = [];
      }
    });
}
<div class="ng-autocomplete">
  <ng-autocomplete 
    [data]="data"
    [searchKeyword]="keyword"
    (selected)='selectEvent($event)'
    (inputChanged)='onChangeSearch($event)'
    (inputFocused)='onFocused($event)'
    [itemTemplate]="itemTemplate"
    [notFoundTemplate]="notFoundTemplate">                                 
  </ng-autocomplete>

  <ng-template #itemTemplate let-item>
  <a [innerHTML]="item.name"></a>
  </ng-template>

  <ng-template #notFoundTemplate let-notFound>
  <div [innerHTML]="notFound"></div>
  </ng-template>
 </div>

检查更新的小提琴以及我的代码有什么问题吗?

0 个答案:

没有答案