3

我的 Angularjs 应用程序有问题,无法弄清楚问题出在哪里。

plunker 上查看

当我单击按钮时,它应该运行 iCheck() 插件,但它没有

4

2 回答 2

9

可以在此处找到更好的 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);
                    });
                }
            });
        });
    }
};
于 2014-04-07T23:21:12.850 回答
1

您应该做一件事以使一切正常:强制 AngularJS 实际使用 jQuery

AngularJS 在其源代码中包含 jQlite,但它与 jQuery 不同。如果您在angular.js之前包含 jQuery,那么 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 之前)

工作小插曲

于 2014-01-21T08:03:09.643 回答