javascript - 如何使用 ngx-chips 设置初始值
问题描述
我在设置初始值时遇到问题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
. 我真正想要的是当用户点击标签输入上的一些初始值的编辑按钮时。我究竟做错了什么 ?。
解决方案
有一个(onFocus)="onInputFocused($event)"
事件。在那里,您可以调用您的服务器并使用检索到的示例数据填写表格。例如
this.service.getTicketTypes().then(tt=>{
this.form.controls.ticketTypes.setValue(JSON.parse(tt));
})
推荐阅读
- android - FXCollections in over Android
- python - D 盘上的 Python 与 VS Code 连接
- apache-kafka - Kafka接收器连接器-> postgres,avro JSON数据失败
- python - 是否可以从 python 中的字符串中获取这个 df['homes']+df['flats']?
- javascript - 以 HTML 格式从 API 请求中获取和显示数据
- python - Python从Mysql中的传感器插入值
- amazon-web-services - 来自 Heroku / AWS 的外部 API 的访问被拒绝
- javascript - 无法调用外部 js 文件中的 JS 函数 - 未捕获的引用错误
- c++ - FLTK闪烁动画
- c++ - 使用 boost rtree 进行加权距离的最近点搜索