ng checked和ng change单选按钮不一起工作-angularjs
js 和htmlng checked和ng change单选按钮不一起工作-angularjs,angularjs,angularjs-ng-model,angularjs-ng-change,angularjs-ng-checked,Angularjs,Angularjs Ng Model,Angularjs Ng Change,Angularjs Ng Checked,js 和html {{radius.name} 注意,“2英里”无线电输入根据半径范围结构进行检查。为什么ng更改不会触发该功能 如果我添加ng模型,该函数将触发,但选中的ng不起作用。这是因为您没有使用ng模型。: <div class="radio" ng-repeat="radius in radii" id="selectradius-{{radius.id}}"> <label> <input type="radio" name="r
{{radius.name}
注意,“2英里”无线电输入根据半径范围结构进行检查。为什么ng更改不会触发该功能
如果我添加ng模型,该函数将触发,但选中的ng不起作用。这是因为您没有使用
ng模型。
:
<div class="radio" ng-repeat="radius in radii" id="selectradius-{{radius.id}}">
<label>
<input type="radio" name="radius"
ng-change="handleRadioClick(selectedRadius)"
ng-model="radius.checked">
{{radius.name}}
</label>
</div>
$scope.radii = [
{id:.25, name:"1/4 Mile"},
{id:.5, name:"1/2 Mile"},
{id:1, name:"1 Mile"},
{id:2, name:"2 Mile"},
{id:3, name:"3 Mile"},
{id:4, name:"4 Mile"},
{id:5, name:"5 Mile"}
];
// selected value is {id:2, name:"2 Mile"}
$scope.selectedRadius = $scope.radii[3];
HTML
<div class="radio" ng-repeat="radius in radii" id="selectradius-{{radius.id}}">
<label>
<input type="radio" name="radius"
ng-change="handleRadioClick(radius)"
ng-model="selectedRadius"
ng-value="radius">
{{radius.name}}
</label>
</div>
这是因为我们正在改变
希望这有帮助。干杯 使用默认值,一切都会像魔咒一样工作,不需要$watch scope或任何东西。。。是的,您需要ng型号
- ng模型-所有功能都正常吗
- ng checked-确保已选中属性present
- ng更改-更改时将触发您的功能
<input type="checkbox"
ng-model="row.active"
ng-checked="row.active"
ng-true-value="1"
ng-false-value="0"
ng-change="update(row)"
/>
<!-- test -->
{{ row.active }}
$scope.update = function(row) {
console.log('row.active');
}
ng change
指令要求存在ng model
指令
从文档中:
ngChange
注意,本指令要求提供ngModel
ng model
和ng checked
指令不应一起使用
从文档中:
NGCHECK
如果ngChecked
中的表达式为truthy,则在元素上设置checked属性
请注意,此指令不应与ngModel
一起使用,因为这可能导致意外行为
而是从控制器设置所需的初始值
有关详细信息,请参阅
ng checked
中,它说:“请注意,此指令不应与ngModel一起使用,因为这可能会导致意外行为。”ngModel
和ngChecked
不能一起使用。看见
<div class="radio" ng-repeat="radius in radii" id="selectradius-{{radius.id}}">
<label>
<input type="radio" name="radius"
ng-change="handleRadioClick($parent.selectedRadius)"
ng-model="$parent.selectedRadius"
ng-value="radius">
{{radius.name}}
</label>
</div>
<input type="checkbox"
ng-model="row.active"
ng-checked="row.active"
ng-true-value="1"
ng-false-value="0"
ng-change="update(row)"
/>
<!-- test -->
{{ row.active }}
$scope.update = function(row) {
console.log('row.active');
}