【发布时间】:2020-12-23 13:31:03
【问题描述】:
我有一个要求,我正在使用多选的角度形式,每行也有徽标。 单击此徽标时,我想加载模态弹出组件,我正在关注 Stackblitz 演示,用于在单击元素时调用 app.component 中的模态组件。
我关注的demo链接:Bootstrap modal Stackblitz Demo
我正在实施的解决方法演示如下:Workaround Demo Stackblitz
使用 openModal() 函数单击徽标时出现的错误是未定义的对象。
如何在使用角度形式时纠正这个问题?
下面是sn-p的代码:
多选表单组件
@Component({
selector: 'formly-field-multiselect',
template: `<br><p-multiSelect [options]="to.options"
[formControl]="formControl"
[formlyAttributes]="field"
[showClear]="!to.required" >
<ng-template let-item pTemplate="item">
<div>{{item.label}}</div>
<div>
<i class="pi pi-check" (click)="to.openModal()"></i>
</div>
</ng-template>
</p-multiSelect>
`,
})
app.component.ts在其中调用了模态组件(calenderComponent)
fields: FormlyFieldConfig[] = [
{
key: "select",
type: "multiselect",
templateOptions: {
multiple: false,
placeholder: "Select Option",
options: [
{ label: "Select City", value: null },
{ label: "New York", value: { id: 1, name: "New York", code: "NY" } },
{ label: "Rome", value: { id: 2, name: "Rome", code: "RM" } },
{ label: "London", value: { id: 3, name: "London", code: "LDN" } },
{
label: "Istanbul",
value: { id: 4, name: "Istanbul", code: "IST" }
},
{ label: "Paris", value: { id: 5, name: "Paris", code: "PRS" } }
],
openModal() {
this.modalRef = this.modalService.show(CalenderComponent, {
initialState: {
title: 'Modal title'
}
});
},
}
}
【问题讨论】:
-
你是如何得到你在 stackblitz 中提到的错误的?
-
我单击 中的多选行的图标,然后我得到错误,
标签: javascript angular ngx-formly