我有以下HTML(使用类固醇构建混合应用程序):
<select>
<option value="1">Once a day</option>
<option value="2">Once a week</option>
</select>
<li class="item item-checkbox">
<label class="checkbox">
<input type="checkbox" value="resumes">
</label>
Resumes
</li>
<li class="item item-checkbox">
<label class="checkbox">
<input type="checkbox" value="linkedin">
</label>
LinkedIn
</li>
<li class="item item-checkbox">
<label class="checkbox">
<input type="checkbox" value="mycco">
</label>
myCCO
</li>
Angular中是否有办法从select
和所有选中的复选框中获取所选值?
答案 0 :(得分:2)
确保只为每个
添加ng-model<select ng-model="data.period">
<option value="1">Once a day</option>
<option value="2">Once a week</option>
</select>
<li class="item item-checkbox">
<label class="checkbox">
<input ng-model="data.resumes" type="checkbox" value="resumes">
</label>
Resumes
</li>
<li class="item item-checkbox">
<label class="checkbox">
<input ng-model="data.linkedin" type="checkbox" value="linkedin">
</label>
LinkedIn
</li>
<li class="item item-checkbox">
<label class="checkbox">
<input ng-model="data.mycco" type="checkbox" value="mycco">
</label>
myCCO
</li>
在您的控制器中:
// Contains all your data
$scope.data = {};
但是,您可以考虑进行整个表单验证/提交,例如https://scotch.io/tutorials/angularjs-form-validation