AngularJS directive only when the condition is true
问题 I am going to have a contextmenu directive in ng-repeat items. Based on whether a condition is true, the directive should be applied. How do I put a condition like only when item.hasMenu == true then apply the directive ? <ul ng-controller="ListViewCtrl" > <li contextmenu ng-repeat="item in items">{{item.name}} </li> </ul> EDIT This seems to have worked for me. First the directive. app.directive('menu',function(){ return { restrict : 'A', link : function(scope,element,attrs){ if(scope.hasMenu