Reputation: 755
i need to include a directive as a class:
and i need to use this pattern:
ng-class='{"some-directive":1'}
but unfortunately the directive can only be registered in the pattern below (try it in the plunker link above):
class='some-directive'
The main problem is I want to register(include) the directive only to the "rename" option of my context menu:
<li ng-class="{'renameDirective':(menu.name == 'Rename')}" ng-repeat="menu in contextmenu
How would I achieve that?.. what's tougher is that I want to add an argument in renameDirective.. maybe like this :
ng-class="{'renameDirective
: directiveArg':(menu.name == 'Rename')}"
is something like this: <div renameDirective="directiveArg"></div>
UPDATE:
As a wordy workaround, the code below can temporarily solve the issue. It is open for more improvements (I guess taking advantage of the ng-class directive is best, shortest/ cleanest approach).
<ul>
<li ng-repeat="menu in contextmenu">
<div ng-switch on="menu">
<div ng-switch-when="Rename">
<button some-directive="Rename">button{{$index}}</button>
</div>
<div ng-switch-default>
<button>button{{$index}}</button>
</div>
</div>
</li>
</ul>
I had this semi-duplicate post as my reference here
Upvotes: 2
Views: 144
Reputation: 43947
<button class="{{menu.name=='Rename' && 'some-directive'}}">button2</button>
Upvotes: 1