Angular 角度4@ngui自动完成

Angular 角度4@ngui自动完成,angular,autocomplete,ngui,Angular,Autocomplete,Ngui,我正在尝试在Angular 4项目中使用库@ngui autocomplete。我使用表单既可以在数据库中创建新条目,也可以更新/编辑现有条目。 自动完成输入的代码如下所示: <div [ngClass]="{ 'form-group': true, 'row' : true, 'has-danger': incidentForm.get('doctor').invalid && ( incidentForm.get(

我正在尝试在Angular 4项目中使用库@ngui autocomplete。我使用表单既可以在数据库中创建新条目,也可以更新/编辑现有条目。 自动完成输入的代码如下所示:

<div [ngClass]="{
              'form-group': true, 'row' : true,
              'has-danger': incidentForm.get('doctor').invalid && ( incidentForm.get('doctor').touched || incidentForm.get('doctor').dirty ),
              'has-success': incidentForm.get('doctor').valid && ( incidentForm.get('doctor').dirty || incidentForm.get('doctor').touched )
           }">
  <label for="doctor" class="col-sm-2 col-form-label">Ιατρός:</label>
  <div class="col-6">

    <input ngui-auto-complete [ngClass]="{
              'form-control': true,
              'form-control-danger': incidentForm.get('doctor').invalid && ( incidentForm.get('doctor').touched || incidentForm.get('doctor').dirty ),
              'form-control-success': incidentForm.get('doctor').valid && ( incidentForm.get('doctor').dirty || incidentForm.get('doctor').touched )
              }"
           name="doctor" formControlName="doctor"
           id="doctor" [source]="doctors"
           autocomplete="off"
           [list-formatter]="'lastName firstName'"
           value-formatter="lastName firstName"
           select-value-of="id"
           required >

    <!-- VALIDATION -->
    <div class="form-control-feedback"
         *ngIf="incidentForm.get('doctor').hasError('required') && incidentForm.get('doctor').touched">
      {{ validationMessages.doctor.required }}
    </div>
    <!-- END OF VALIDATION -->
  </div>
</div>
为了创建条目,一切都按预期进行。 但是,当我更新现有条目时,需要使用命令将值设置为“自动完成输入组件”

this.incidentForm.get('doctor').setValue(response.doctor);
虽然form.value在输入字段中是正确的,但我得到: [对象对象]而不是命令中声明的“lastName firstName”

value-formatter="lastName firstName"
我想我遗漏了一些非常简单的东西,但我无法得到它。

您需要传递
[(ngModel)]
内部输入


因为它是自动完成的,并且作为一个下拉列表工作,所以您需要绑定您的模型,这就是您可以搜索数据并使用双向数据绑定选择该数据的方式

<input ngui-auto-complete name="doctor" 
       formControlName="doctor" 
       id="doctor" 
       [source]="doctors" 
       autocomplete="off" 
       [list-formatter]="'lastName firstName'" 
       value-formatter="lastName firstName" 
       [(ngModel)] = "Doctor" 
       required>

您需要传递
[(ngModel)]
内部输入


因为它是自动完成的,并且作为一个下拉列表工作,所以您需要绑定您的模型,这就是您可以搜索数据并使用双向数据绑定选择该数据的方式

<input ngui-auto-complete name="doctor" 
       formControlName="doctor" 
       id="doctor" 
       [source]="doctors" 
       autocomplete="off" 
       [list-formatter]="'lastName firstName'" 
       value-formatter="lastName firstName" 
       [(ngModel)] = "Doctor" 
       required>

解决方案很简单。刚刚加上

 display-property-name="lastName firstName"
i、 e


解决方案很简单。刚刚加上

 display-property-name="lastName firstName"
i、 e



能否将getIncidentByID的代码粘贴到*服务中,以及来自该服务的json响应?对象接收正确。我可以在form.value中看到它。问题出在输入自动完成字段,它没有显示“lastName firstName”,而是显示了我理解的[object object],这就是为什么我要求您粘贴JSON response并查看vice codecan您可以粘贴*服务中getIncidentByID的代码以及来自该服务的JSON响应吗?对象接收正确。我可以在form.value中看到它。问题是在输入自动完成字段,它显示的不是“lastName firstName”,而是我理解的[object object],这就是为什么我要求您粘贴JSON responce并查看设备代码这应该如何实现?因为它是自动完成的,并且作为下拉菜单工作,所以您需要绑定您的模型,这就是您可以搜索数据并使用双向数据绑定来选择该数据的方式。您可以展示输入应该如何形成吗?我问这些问题是为了提高你答案的质量,这样我就可以投票了。作为SO答案的一般规则;信息越多越好。我认为投票人(不是我)觉得你的答案有点简单。在上面的例子中,你可以在ngui autocomplete you need[source]中看到,它返回数据,模型决定数据的返回类型,你需要数据的格式。这里是模型。这应该如何实现?因为它是自动完成的,并且作为一个下拉列表工作,所以您需要绑定您的模型,这就是您可以搜索数据并使用双向数据绑定选择该数据的方式。您可以演示输入应如何形成吗?我问这些问题是为了提高你答案的质量,这样我就可以投票了。作为SO答案的一般规则;信息越多越好。我认为投票人(不是我)觉得你的答案有点简单。在上面的例子中,你可以在ngui autocomplete you need[source]中看到,它返回数据,模型决定数据的返回类型,你需要数据的格式。这里医生是模型。如果我有这个下拉列表,我如何通过传递int而不是object@mixtou来获取数据的id或主键如果我有这个下拉列表,我如何通过传递int而不是object@mixtou来获取数据的id或主键