Javascript 角度检查复选框是否为从函数/方法内部检查
我使用Angular 4,在我的模板上有一个复选框和一个div 在我的.ts文件中,我有两个函数Javascript 角度检查复选框是否为从函数/方法内部检查,javascript,angular,typescript,angular2-template,Javascript,Angular,Typescript,Angular2 Template,我使用Angular 4,在我的模板上有一个复选框和一个div 在我的.ts文件中,我有两个函数 // html <input type="checkbox" class="custom-control-input" (change)="function2($event)"> <div (click)="function1()">some text here</div> 从function1如何检查复选框是否选中?获取function1()中的值的方法之一
// html
<input type="checkbox" class="custom-control-input" (change)="function2($event)">
<div (click)="function1()">some text here</div>
从function1如何检查复选框是否选中?获取function1()中的值的方法之一是使用模板变量 然后您可以执行以下操作: 一,。 HTML
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<div (click)="function1(input)">some text here</div>
二,。
HTML
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<div (click)="function1(input)">some text here</div>
获取function1()中的值的方法之一是使用模板变量 然后您可以执行以下操作: 一,。 HTML
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<div (click)="function1(input)">some text here</div>
二,。
HTML
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<input #input type="checkbox" class="custom-control-input" (change)="function2($event)">
<div (click)="function1(input)">some text here</div>
将Id属性添加到复选框
<input id='check1' type="checkbox" class="custom-control-input" (change)="function2($event)">
将Id属性添加到复选框
<input id='check1' type="checkbox" class="custom-control-input" (change)="function2($event)">
angular提供了一种直接处理表单的方法,这是有原因的。实际上,它提供了两种方式(模板驱动表单和反应式表单),并且不要忘记动态创建表单。我建议你在回答中使用其中一个。你的建议将不切实际,或者至少很难在更大的表单组件中维护。30个表单元素的方法看起来如何?还是100个动态创建的输入?@lexith,谢谢!在五月的回答中,我说了“一条路”,意思是“其中一条路”,我并不是有意说这条路。我将尝试在我的答案中添加您的建议:)angular提供了一种直接处理表单的方法,这是有原因的。实际上,它提供了两种方式(模板驱动表单和反应式表单),并且不要忘记动态创建表单。我建议你在回答中使用其中一个。你的建议将不切实际,或者至少很难在更大的表单组件中维护。30个表单元素的方法看起来如何?还是100个动态创建的输入?@lexith,谢谢!在五月的回答中,我说了“一条路”,意思是“其中一条路”,我并不是有意说这条路。我将尝试在我的答案中添加您的建议:)