【发布时间】:2018-05-04 02:29:28
【问题描述】:
目标:用户点击一个复选框,启动我的函数checkedAmPrompt。如果用户在提示上点击取消,它将取消选中他们选中的框。如果他们点击 OK,它将按计划继续并保持检查状态。目前它运行良好,只是我找不到取消选中该框的方法。
相关代码如下:
webpage.component.html -- 请注意,这是在一个表格中,其中有一个对应于每一行的复选框。
<td><input type="checkbox" class="form-control" id="checkedAm" (change)="checkedAmPrompt($event)"></td>
webpage.component.ts
// Prompt to confirm checkbox action
checkedAmPrompt(event: any) {
const confirm = prompt('If you are certain that what you are doing is correct please type CONFIRM to continue.');
// What to do if user selects cancel to pop-up, otherwise user confirms action
if (confirm == null) {
console.log('User hit cancel.');
// ***** WANT TO PUT LOGIC TO UNCHECK HERE *****
} else if (confirm.toLowerCase() === 'confirm') {
// submit the changes if they type in confrim
console.log('changes submitted!')
} else {
// if they misspell confirm let them know
console.log('Incorrect spelling.');
}
}
取消选中 HTML 框的逻辑将替换 // ***** WANT TO PUT LOGIC TO UNCHECK HERE *****
请注意,我没有使用 JavaScript,我的 HTML 文件仅包含 HTML/Angular,并且所有函数都由组件打字稿引用。我对一切都很陌生,所以如果这是一个糟糕的选择,请原谅。
【问题讨论】:
-
一般来说,Angular HTML 应该反映应用程序的当前状态。我的猜测是你需要使用类似
$scope.checkedAm = false;并相应地更改 HTML:docs.angularjs.org/api/ng/directive/ngChecked
标签: angular