Angular Material 手风琴在首次渲染时不会关闭。
创始人
2024-10-19 18:31:41
0

要解决Angular Material手风琴在首次渲染时不会关闭的问题,可以通过设置默认打开的面板索引来强制关闭它。

首先,在组件的类中添加一个变量来保存默认打开的面板索引:

import { Component } from '@angular/core';

@Component({
  selector: 'app-accordion',
  templateUrl: './accordion.component.html',
  styleUrls: ['./accordion.component.css']
})
export class AccordionComponent {
  defaultPanelIndex: number = -1;
}

然后,在HTML模板中为手风琴组件绑定defaultPanelIndex变量:


  
    
      
        Panel 1
      
    
    

This is the content of panel 1.

Panel 2

This is the content of panel 2.

在上述示例中,[selectedIndex]="defaultPanelIndex"defaultPanelIndex变量绑定到手风琴组件的selectedIndex属性上。defaultPanelIndex的初始值为-1,这将导致所有面板都关闭。当手风琴首次渲染时,会强制关闭所有面板。

如果你想要默认打开一个面板,只需将defaultPanelIndex设置为该面板的索引即可。例如,将defaultPanelIndex设置为0将默认打开第一个面板。

defaultPanelIndex: number = 0;

这样,当手风琴首次渲染时,第一个面板将被打开,其他面板将保持关闭状态。

相关内容

热门资讯

透视指南书!德普之星透视辅助软... 透视指南书!德普之星透视辅助软件,德普之星有辅助软件吗(透视)其实真的有透视脚本(哔哩哔哩)运德普之...
透视指南!wepoker科技辅... 透视指南!wepoker科技辅助器,wepoker透视脚本免费使用视频(透视)切实是真的挂(哔哩哔哩...
透视法子!aapoker怎么设... 透视法子!aapoker怎么设置抽水,aapoker安装包怎么使用(透视)真是存在有脚本工具(哔哩哔...
透视项目!德州圈脚本,hhpo... 透视项目!德州圈脚本,hhpoker底牌透视脚本(透视)好像是有挂(哔哩哔哩)1、hhpoker底牌...
透视诀窍!wepoker怎么增... 透视诀窍!wepoker怎么增加运气,wepoker免费透视(透视)都是存在有透视技巧(哔哩哔哩)1...
透视演示!wepoker透视脚... 透视演示!wepoker透视脚本苹果版,德州私人局怎么透视(透视)好像真的是有挂(哔哩哔哩);1、游...
透视练习!wepoker高级辅... 透视练习!wepoker高级辅助,wepoker透视脚本安卓(透视)一贯真的是有透视器(哔哩哔哩)1...
透视教材!pokemmo内置修... 透视教材!pokemmo内置修改器,wepoker辅助分析器(透视)切实是有挂(哔哩哔哩)1、每一步...
透视法子!德州局hhpoker... 透视法子!德州局hhpoker,hhpoker免费透视脚本(透视)确实真的是有脚本神器(哔哩哔哩)h...
透视操作!hhpoker德州牛... 透视操作!hhpoker德州牛仔视频,hhpoker智能辅助插件(透视)本来是真的挂(哔哩哔哩)1、...