tristate复选框angular js指令在IE 11中不起作用

时间:2016-12-20 22:27:21

标签: angularjs angularjs-directive internet-explorer-11

我从this帖子中获取了解决方案以实现三态复选框。它适用于chrome / firefox但不适用于IE(特别是使用IE 11)。 有人可以告诉我为什么http://jsfiddle.net/xJhEG/25/适用于所有浏览器但在IE上失败了吗?

var myApp = angular.module('myApp',[]);
/**
 * Directive for an indeterminate (tri-state) checkbox.
 * Based on the examples at https://stackoverflow.com/questions/12648466/how-can-i-get-angular-js-checkboxes-with-select-unselect-all-functionality-and-i
 */

myApp
  .directive('indeterminate', [function() {
    console.log("funct called!");
    return {
      require: '?ngModel',
      link: function(scope, el, attrs, ctrl) {        
        ctrl.$formatters = [];
        ctrl.$parsers = [];
        ctrl.$render = function() {
          var d = ctrl.$viewValue;
          el.data('checked', d);
          console.log("d = " + d);
          switch(d){
          case true:
            el.prop('indeterminate', false);
            el.prop('checked', true);
            break;
          case false:
            el.prop('indeterminate', false);
            el.prop('checked', false);
            break;
          default:
            el.prop('indeterminate', true);
          }
        };
        el.bind('click', function() {
          var d;
          switch(el.data('checked')){
          case false:
            console.log("f -> t");
            d = true;
            break;
          case true:
            console.log("t -> n");
            d = null;
            break;
          default:
            console.log("n -> f");
            d = false;
          }
          ctrl.$setViewValue(d);
          scope.$apply(ctrl.$render);
        });
      }
    };
  }])

function MyCtrl($scope) {
    $scope.state = true;
}

0 个答案:

没有答案