我的模板遍历组并呈现一些嵌套元素,列出e.t.c.:
<ul>
<li *ngFor="let group of groups">
...
<ul class="list_devices">
<li class="row list_devices_header" *ngIf="getNumberOfDevicesInGroup(group.id) > 0">
...
</li>
<li class="row" *ngFor="let item of devices | matchesGroup:group.id">
...
</li>
</ul>
</li>
</ul>
问题是,当我从数组中删除组时:
delete this.groups[index]
渲染的布局仍然存在,并抛出错误:
DeviceListComponent.html:122 ERROR TypeError: Cannot read property 'id' of undefined
对于使用已删除对象的嵌套指令。
也许我做错了。
我想删除一个组并删除所有嵌套元素。
我该怎么做才对?
非常感谢。