0

我只是想样式里面我是用http://uniformjs.com与angularjs jQuery插件的复选框Unform jQuery插件默认复选框。如何风格的浏览器使用自定义指令在angularjs

这里的复选框输入元素我想用插件方式:

<label><input type="checkbox" plugin-uniform id="inline">&nbsp;Inline editing</label> 

这里是对自定义指令,我为写:

myApp.directive('pluginUniform', function() { 
     return { 
      restrict: 'A', 
      link: function(scope, element, attrs) { 
       Layout.initUniform(); 
      } 
     }; 
    }); 

这里是Layout.initUnform () code:

var Layout = function() { 

    //other stuff 

      initUniform: function (els) { 
       if (els) { 
        jQuery(els).each(function() { 
          if ($(this).parents(".checker").size() == 0) { 
           $(this).show(); 
           $(this).uniform(); 
          } 
         }); 
       } else { 
        handleUniform(); 
       } 
      } 

    function handleUniform() { 
     if (!jQuery().uniform) { 
      return; 
     } 
     var test = $("input[type=checkbox]:not(.toggle), input[type=radio]:not(.toggle, .star)"); 
     if (test.size() > 0) { 
      test.each(function() { 
        if ($(this).parents(".checker").size() == 0) { 
         $(this).show(); 
         $(this).uniform(); 
        } 
       }); 
     } 
    } 

    //other stuff 

    } 

我有uniform.default.cssjquery.uniform.js已经到位。

有人能告诉我如何使用自定义指令在angularjs中将浏览器默认复选框样式设置为http://uniformjs.com jQuery插件复选框样式?

回答

1

你缺少els说法,当你调用Layout.initUniform()

由于指令的链接功能已经暴露元素作为一个jQuery对象时,jQuery库在页面角库之前包括你并不真的需要你的布局功能

handleUnform功能中有几个缺点。

要检查plugun的存在应该做if($.fn.pluginName)。另外,如果你有很多绑定到它的指令元素,每次指令运行时你都会遍历所有的元素。

试试这个:

myApp.directive('pluginUniform', function() { 
    return { 
     restrict: 'A', 
     link: function(scope, element, attrs) { 
      /* element is jQuery object*/ 
      if (!element.parents(".checker").length) { /* size() is deprecated */ 
       element.show().uniform();       
      } 
     } 
    }; 
}); 
+0

是的,它现在的工作,谢谢:)。但它现在在控制台上给我这个错误'TypeError:undefined不是''input type =“复选框”plugin-uniform =“”id =“autoopen”>'和''。 – skip 2014-09-13 21:51:18

+1

您是否在页面中包含jQuery之前包含jQuery?这是需要使'angular.element'使用jQuery – charlietfl 2014-09-13 21:53:27

+0

是的,它在angularjs库之前。 – skip 2014-09-13 21:54:54

相关问题