我有一個要求,其中我使用角度形式的多選,每行也有徽標。單擊此徽標時,我想加載模態彈出組件,我正在遵循 Stackblitz 演示,以便在單擊元素時調用 app.component 中的模態組件。我關注的演示鏈接: Bootstrap modal Stackblitz Demo我正在實施的解決方法演示如下:解決方法演示 Stackblitz我使用openModal()函數單擊徽標時遇到的錯誤是未定義的對象。在正式使用角度時如何糾正這個問題?以下是代碼片段:多選形式組件@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' } }); }, }}
Bootstrap 模態彈出組件在單擊角度形式元素時不起作用
HUX布斯
2024-01-18 09:52:45