0

私はこのスレッドを読むだけでなく、stackoverflow を見回しましたが、まだ成功していません。AngularJS Web アプリで iCheck を使用しようとしていますが、まだ通常のチェックボックスしか表示されません。私もrequire.jsを使用しています。これを機能させる方法はありますか?

ありがとう!

HTML:

<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から):

    (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);
                              });
                          }
                      });
                  });
              }
          };
      });
})();
4

2 に答える 2

0

メインの html ファイルに iCheck コンポーネントをロードしていることを再確認してください。

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

于 2014-12-01T22:05:39.057 に答える
0

インポートするメインのAngularモジュールで確認してください

ui.check

お気に入り

angular.module("myApp",['ui.check'])
于 2014-12-01T23:11:46.540 に答える