問題解決!在https://github.com/fronteed/icheck/issues/62
app.directive('icheck', function($timeout, $parse) {
return {
require: 'ngModel',
link: function($scope, element, $attrs, ngModel) {
return $timeout(function() {
var value;
value = $attrs['value'];
$scope.$watch($attrs['ngModel'], function(newValue) {
$(element).iCheck('update');
})
return $(element).iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue'
}).on('ifChanged', function(event) {
if ($(element).attr('type') === 'checkbox' && $attrs['ngModel']) {
$scope.$apply(function() {
return ngModel.$setViewValue(event.target.checked);
});
}
if ($(element).attr('type') === 'radio' && $attrs['ngModel']) {
return $scope.$apply(function() {
return ngModel.$setViewValue(value);
});
}
});
});
}
};
});
使用(wajatimur)的I確認指令,然後在NG-重複:使用$父在NG-模型,因爲ngRepeat將爲其創造兒童的新領域(
<tbody>
<tr ng-repeat="school in schools">
<td>{{school.Location}}</td>
<td>{{school.Type}}</td>
<td>{{school.Name}}</td>
<td class="school-action text-center">
<label>
<input icheck type="radio" name="iCheck" class="flat-red" ng-value={{$index}} ng-model="$parent.schoolIndex" ng-change="changeFaculty(schoolIndex)"/>
</label>
</td>
</tr>
以及原型繼承如何影響範圍),所以ng-change只會觸發一次事件。