使用angular的DropDown指令

米格尔·莫拉(Miguel Moura)

对于下拉菜单,我有以下指令(http://jsfiddle.net/77f4m6n5/2/):

<a href="#" dropdown>Open
  <ul>
    <li>Item 1</li>
    <li>Item 2</li>
  </ul>
</a>

指令如下:

app.directive("dropdown", dropdown);

function dropdown() {

  var dropdown = {
    link: link,
    replace: false,
    restrict: "A"
  };

  return dropdown;

  function link(scope, element, attributes) {   
    element.bind("click", function(event)   {                                                
        element.children().toggleClass("active");
   });  
  } 
} 

我可以创建这样的指令,但更多地以“有角度的方式”吗?我想我应该为链接指定一个指令,为下拉菜单指定另一个指令,不是吗?

麦克风。d

这将是更加有角度的方法:

.directive('dropdown', function() {
  return {
    link: function(scope, element, attrs) {
      element.bind("click", function(event)   {                                                
        element.children().toggleClass("active");
    },
    replace: false,
    restrict: 'A'
  };
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章