2

plunker

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

1 Answer 1

1
<button class="{{menu.name=='Rename' && 'some-directive'}}">button2</button> 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for that idea, and for the quick response. However, can you improve that expression so that some-directive accepts arguments? it's always good so we can parameterize.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.