2014-12-01 58 views
-1

我看了看周圍的計算器以及閱讀this thread但仍然沒有成功。我正在嘗試在我的AngularJS網絡應用程序中使用iCheck,但我仍然只看到常規復選框。我也使用require.js。任何想法如何讓這個工作?iCheck與AngularJS和RequireJS

謝謝!

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

你解決找你的問題? – 2014-12-08 22:08:09

+0

我從來沒有解決我的問題,但我選擇使用我自己的CSS樣式複選框和單選按鈕,而不是iCheck。 – 2015-04-03 16:54:04

回答

0

仔細檢查你正在裝載I檢查部件在您的主HTML文件:

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

0

檢查你的主角模塊中是否有imp奧廷

ui.check 

angular.module("myApp",['ui.check'])