【问题标题】:How to set initial value using ngx-chips如何使用 ngx-chips 设置初始值
【发布时间】:2019-11-04 03:20:26
【问题描述】:

我在tag-input 上设置初始值时遇到问题。当admin 点击编辑按钮tag-input 必须从database 获得一些初始值。我怎样才能做到这一点 ?这是我的代码示例:

<tag-input formControlName="ticketTypes">
  <tag-input-dropdown
    [showDropdownIfEmpty]="true"
    [dynamicUpdate]="false"
    [focusFirstElement]="true"
    [displayBy]="'name'"
    [identifyBy]="'name'"
    [autocompleteItems]="ticketType"
 >
   <ng-template let-item="item" let-index="index">
     {{ item.name }}
   </ng-template>
 </tag-input-dropdown>
</tag-input>

这里有一些ts:

setHall() {
    if (this.halls !== undefined) {
      this.loadFirst = false;
      this.halls.forEach(hall => {
        console.log(hall.ticketTypes);
        this.formArray.push(
          this.fb.group({
            name: hall.name,
            availableWindowCount: hall.availableWindowCount,
            totalWindowCount: hall.totalWindowCount,
            ticketTypes: []
          })
        );
      });
    }
  }

当用户单击编辑按钮时调用上述函数,它会抛出一些数据并将其设置在表单组中。但我需要在tag-input 中输入一些值。我真正想要的是当用户点击标签输入上的一些初始值的编辑按钮时。我究竟做错了什么 ?。

【问题讨论】:

    标签: javascript angular ngx-chips


    【解决方案1】:

    有一个(onFocus)="onInputFocused($event)" 事件。在那里,您可以调用您的服务器并使用检索到的示例数据填写表格。例如

    this.service.getTicketTypes().then(tt=>{
        this.form.controls.ticketTypes.setValue(JSON.parse(tt));
    })
    

    【讨论】:

      猜你喜欢
      • 2019-08-22
      • 1970-01-01
      • 2021-12-15
      • 2020-01-14
      • 2023-01-30
      • 2011-12-22
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多