我在每行中都有一个列表和一个复选框。我希望每当我单击一个复选框时,对象都需要根据复选框状态进行相应的更新,但是当我在复选框上点击时使用下面的内容,却遇到无法设置属性“ 已选中”的异常未定义或空引用可以帮助我在哪里做mi-stack
google(), mavenLocal() and jcenter()
export class Custom{
name: string
empoloyeeID: number
checked:boolean
}
export class CheckboxListPage {
contacts:Array<Custom> = [];
constructor(public navCtrl: NavController, public navParams: NavParams) {
let customObj1 = new Custom();
customObj1.empoloyeeID = 1;
customObj1.name = "Ramakrishna";
let customObj2 = new Custom();
customObj2.empoloyeeID = 2;
customObj2.name = "Ramakrishna2";
this.contacts.push(customObj1);
this.contacts.push(customObj2);
}
updateCucumber(contact){
this.contacts[contact.empoloyeeID].checked = !contact.checked;
}
答案 0 :(得分:1)
无需添加事件侦听器即可更新模型(联系人)的值。当您在html文件中具有bind(双向)该属性时。