以编程方式打开扩展面板,无需单击

问题描述

有什么方法可以触发openAll方法...以便我可以以编程方式打开所有面板... 使用openAll方法... 我尝试制作一个函数,然后在ngOnint中调用函数,然后抛出一些错误

错误 错误:无法读取未定义的属性'openAll'

请帮助

enter image description here

HTML

    <mat-accordion class="example-headers-align" multi>
<!-- #enddocregion multi -->
  <mat-expansion-panel>
    <mat-expansion-panel-header>
      <mat-panel-title>
        Personal data
      </mat-panel-title>
    </mat-expansion-panel-header>

    <mat-form-field>
      <mat-label>Age</mat-label>
      <input matInput type="number" min="1">
    </mat-form-field>

  </mat-expansion-panel>
<!-- #docregion disabled -->
  <mat-expansion-panel>
<!-- #enddocregion disabled -->
    <mat-expansion-panel-header>
      <mat-panel-title>
        Destination
      </mat-panel-title>
    </mat-expansion-panel-header>

    <mat-form-field>
      <mat-label>Country</mat-label>
      <input matInput>
    </mat-form-field>
  </mat-expansion-panel>
</mat-accordion>

.ts文件

import {Component,ViewChild,OnInit,ElementRef,AfterViewInit,AfterContentinit,AfterContentChecked} from '@angular/core';
import {MatAccordion} from '@angular/material/expansion';

/**
 * @title Accordion with expand/collapse all toggles
 */
@Component({
  selector: 'expansion-expand-collapse-all-example',templateUrl: 'expansion-expand-collapse-all-example.html',styleUrls: ['expansion-expand-collapse-all-example.css'],})
export class ExpansionExpandCollapseAllExample implements OnInit{
  @ViewChild(MatAccordion) accordion: MatAccordion;

  ngOnInit(){
   this.openPanel()
  }
 openPanel(){
    this.accordion.openAll()
 }
}

请参见下图

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...