如何将对象绑定到 ngx-typeahead 的值?

How can i bind object to value of ngx-typehead?

我有这个数组:

let cityArrays = [
  {
    "zip": "60645",
    "city": "Chicago / IL",
    "longitude": "42.008956",
    "latitude": "-87.69634"
  },
  {
    "zip": "60647",
    "city": "Chicago / IL",
    "longitude": "41.921126",
    "latitude": "-87.70085"
  },
}

我怎样才能在 typehead 中显示所有城市,但是当值被选中一个城市时,然后在 typeaheadOnSelect 事件中获取整个对象

<input [(ngModel)]="selectedObject" [typeahead]="cityArrays"  [isAnimated]="true" class="form-control" (typeaheadOnSelect)="select($event)">

根据 specification,这是您需要做的:

    <input
      type="text"
      placeholder="type a value from the list below"
      ngxTypeahead
      class="col-sm-12 form-control"
      [taList]="cityArrays"
      [taListItemField]="['city']"
      taListItemLabel="city"
      (taSelected)="handleStaticResultSelected($event)"
    />

Here 是您正在寻找的 stackblitz 演示。