Angular 2 ngbaccordion以编程方式调用(panelChange)

时间:2018-07-02 23:33:04

标签: angular bootstrap-accordion

我有一个带有panelChange事件的ngbAccordion,效果很好。我想知道的是,如果我可以以编程方式调用该方法,则ngOnInit中是否存在某种方法?

export class UtilityService {
 static checkMinLength(min: number, max: number): ValidatorFn {
     return (c: AbstractControl) => {
         if (c.value && c.value != undefined) {
             return {
                 'checkMinLength': c.value.some((a) => {
                     if (a.itemName.length < min || a.itemName.length > max) { return true; }
                  })
             };
        }
        return null; // LOOK HERE
    }
}
我要调用的

(panelChange)方法:

<ngb-accordion #regularAccordion="ngbAccordion" *ngFor="let item of cartItems; index as i" activeIds={{activeIds}} (panelChange)="toggleAccordion($event, item)">

1 个答案:

答案 0 :(得分:0)

是的。

@ViewChild引用提供一个#regularAccordion,然后使用ngAfterViewInit设置ngb为您提供的侦听器:

@ViewChild ('regularAccordion') regularAccordion: NgbAccordion; (导入 NgbAccordion

ngAfterViewInit() { this.ref.panelChange .subscribe(panel => console.log(panel)); }

工作示例:stackblitz.com