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

Community
  • 1
  • 1
Tyro Hunter
  • 755
  • 1
  • 8
  • 20

1 Answers1

1
<button class="{{menu.name=='Rename' && 'some-directive'}}">button2</button>
AlwaysALearner
  • 43,759
  • 9
  • 96
  • 78
  • 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. – Tyro Hunter Sep 10 '13 at 14:42