javascript - 复选框值不会在 Angular 中从一个组件保留到另一个组件
问题描述
我创造了一个手风琴。在其中,我有一个名为 filter-list 的组件。当我单击标题切换复选框时,它正在切换该组件。但是,它不保留复选框的值。例如,如果我有 5 个复选框并且我只选择了两个然后切换它,它不会保留复选框的值。这是示例代码
应用程序-root.html
enter code here
<h5 (click)="toggle()">Toggle checkboxes</h5>
<app-filter-list *ngIf="isShow"></app-filter-list>
应用程序根.ts
isShow: boolean = false;
toggle(){
this.isShow = !this.isShow;
}
应用过滤器列表.ts
selectDates = [
{ date: "10/08/2020", isChecked: true },
{ date: "30/04/2020", isChecked: true },
{ date: "12/12/2020", isChecked: true },
{ date: "01/03/2020", isChecked: true },
{ date: "02/02/2020", isChecked: true }
]
getDates(index: number){
this.selectDates[index].isChecked = !this.selectDates[index].isChecked;
// this should retain the values of checkboxes
}
应用过滤器列表.html
<div *ngFor="let date of selectDates; let i = index">
<input type="checkbox" value="{{ date.date }}" (change)="getDates(i)"
[checked]="date.isChecked"> {{ date.isChecked }}
</div>
我试过这种方式,但没有运气。
此外,我还尝试使用 @Output() 装饰器,但它仍然没有保留这些值。
任何帮助,将不胜感激。#Angular #javascript #html #ts
解决方案
推荐阅读
- java - 如何检查字符串的开头是否包含数字?
- android - AccessibilityEvent中获取窗口android的详细文本
- javascript - 从数组中随机删除元素直到为空
- javascript - Vue.js Computed/Watch 对视口宽度数据更改没有反应
- python - 了解 find_elements_by_xpath 在 Selenium 中返回的内容
- sql - 有没有办法在“分组”国家之后只显示查询的前 2/n 个?- 大查询 SQL
- html - 如何通过用户资产 ID 访问元素?
- javascript - 一次将 JSON 重复对象发布到服务器而不需要复制?
- angularjs - angularjs 更新到 1.8 后单选按钮值未更新
- android-widget - AppWidgetManager.updateAppWidget() 在某些 Android 11 设备上不起作用