首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AngularJS和RequireJS的iCheck

使用AngularJS和RequireJS的iCheck
EN

Stack Overflow用户
提问于 2014-12-02 05:59:57
回答 2查看 1.1K关注 0票数 0

我已经查看了stackoverflow,也阅读了this thread,但仍然没有成功。我正在尝试在我的AngularJS web应用程序中使用iCheck,但我仍然只能看到常规的复选框。我也在使用require.js。你有什么办法让它工作吗?

谢谢!

HTML:

代码语言:javascript
复制
<label ng-disabled="true" style="font-weight:normal">
                        <input icheck type="checkbox" ng-model="permissions[0]"
                               ng-disabled="true" ng-checked="user.isAdmin" />&emsp;Option #1<br />
                    </label>
                    <label ng-disabled="true" style="font-weight:normal">
                        <input icheck type="checkbox" ng-model="permissions[1]"
                               ng-disabled="true" ng-checked="user.isAdmin" />&emsp;Option #2<br />
                    </label>
                    <label ng-disabled="true" style="font-weight:normal">
                        <input icheck type="checkbox" ng-model="permissions[2]"
                               ng-disabled="true" ng-checked="user.isAdmin" />&emsp;Option #3<br />
                    </label>
                    <label ng-disabled="true" style="font-weight:normal">
                        <input icheck type="checkbox" ng-model="permissions[3]"
                               ng-disabled="true" ng-checked="user.isAdmin" />&emsp;Option #4<br />
                    </label>
                    <label ng-disabled="true" style="font-weight:normal">
                        <input icheck type="checkbox" ng-model="permissions[4]"
                               ng-disabled="true" ng-checked="user.isAdmin" />&emsp;Option #5<br />
                    </label>

指令(来自https://github.com/ciel/icheck):

代码语言:javascript
复制
    (function () {
    /**
     * Create a new module for icheck so that it can be injected into an existing
     * angular program easily.
     */
    angular.module('ui.check', [])
      .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_flat-blue',
                          radioClass: 'iradio_flat-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);
                              });
                          }
                      });
                  });
              }
          };
      });
})();
EN

回答 2

Stack Overflow用户

发布于 2014-12-02 06:05:39

仔细检查是否在主html文件中加载iCheck组件:

<script src="bower_components/iCheck/icheck.min.js"></script>

票数 0
EN

Stack Overflow用户

发布于 2014-12-02 07:11:47

在您要导入的主angular模块中检查

代码语言:javascript
复制
ui.check

喜欢

代码语言:javascript
复制
angular.module("myApp",['ui.check'])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27238132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档