添加 *ngFor 索引值会导致 'Maximum call stack size exceeded'
Adding *ngFor index value causes 'Maximum call stack size exceeded'
我有一个相当简单的视图,它使用 angular 的 *ngFor
挂钩在 html
上循环。我使用 ngx-bootstrap collapse 根据内容 .length
显示 more/less 内容。我遇到的问题是当我折叠一个 more/less 按钮时它们都 collapse/expand.
我已将 let i - index;
添加到 *ngFor
以索引每个按钮,添加这样的 isCollapsed[i]。索引计数正确。
在我的 .ts 文件中,我已经像 isCollapsed = true;
一样进行了初始化,但出现以下错误 Cannot create property '1' on boolean 'true'
。然后我将其更改为 isCollapsed: boolean[] = [];
然后我收到错误 Maximum call stack size exceeded
.
这是我的应用程序视图的 stackBlitz - 任何帮助或修复将不胜感激。
您必须初始化 isCollapsed
。
只需添加:
constructor(){
this.attributes.map(t=> this.isCollapsed.push(false) );
}
Here 是工作样本。
我有一个相当简单的视图,它使用 angular 的 *ngFor
挂钩在 html
上循环。我使用 ngx-bootstrap collapse 根据内容 .length
显示 more/less 内容。我遇到的问题是当我折叠一个 more/less 按钮时它们都 collapse/expand.
我已将 let i - index;
添加到 *ngFor
以索引每个按钮,添加这样的 isCollapsed[i]。索引计数正确。
在我的 .ts 文件中,我已经像 isCollapsed = true;
一样进行了初始化,但出现以下错误 Cannot create property '1' on boolean 'true'
。然后我将其更改为 isCollapsed: boolean[] = [];
然后我收到错误 Maximum call stack size exceeded
.
这是我的应用程序视图的 stackBlitz - 任何帮助或修复将不胜感激。
您必须初始化 isCollapsed
。
只需添加:
constructor(){
this.attributes.map(t=> this.isCollapsed.push(false) );
}
Here 是工作样本。