各行にロゴもある角型の複数選択を使用している必要があります。このロゴをクリックすると、モーダル ポップアップ コンポーネントをロードしたいので、要素のクリック時に app.component で modal-component を呼び出すための Stackblitz Demo に従っています。
私がたどったデモのリンク: Bootstrap modal Stackblitz Demo
私が実装している回避策のデモは次のとおりです:回避策のデモ Stackblitz
関数openModal()でロゴをクリックすると発生するエラーは、未定義のオブジェクトです。
angular形式で作業しているときにこれを修正するにはどうすればよいですか?
コードのスニペットは次のとおりです。
コンポーネントの複数選択
@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>
`,
})
モーダルコンポーネント( calenderComponent )が呼び出されるapp.component.ts
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'
}
});
},
}
}