【发布时间】:2014-01-21 00:03:51
【问题描述】:
【问题讨论】:
标签: angularjs angularjs-directive icheck
【问题讨论】:
标签: angularjs angularjs-directive icheck
可以在此处找到更好的 iCheck 指令:https://github.com/fronteed/iCheck/issues/62 (wajatimur)
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_flat-aero',
radioClass: 'iradio_flat-aero'
}).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);
});
}
});
});
}
};
【讨论】:
您应该做一件事以使一切正常运行:强制 AngularJS 实际使用 jQuery。
AngularJS 在其源代码中包含 jQlite,但它与 jQuery 不同。如果你包含 jQuery before angular.js,那么 Angular 将使用它而不是自己的实现。
因此只需在 index.html 中更改:
<script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script data-require="angular.js@*" data-semver="1.2.9" src="http://code.angularjs.org/1.2.9/angular.js"></script>
(jQuery 在 angular.js 之前)
【讨论】: