Search Posts

Call function within object as parameter for a directive

currently I’m extending my application, so I can give a directive (which generates a table grid) an object for additional buttons to show (for adding other other actions).

Now I can show the button but I need to execute some code as function which should be apply for a click on that button.

The object itself contains strings and function in a mixed way, like this:

  additional-buttons="[{name: 'add', onclick: 'function(){ }', icon: 'fa fa-plus'}]"

My directive template looks like this:

<button ng-repeat="aB in additionalButtons" class="btn btn-primary" ng-click="ab.onclick" type="button">
  <i ng-class="aB.icon" ng-show="aB.icon  != ''" aria-hidden="true"></i>&nbsp;
  <span>{{ 'TABLEGRID_' | uppercase | translate }}</span>

How can I execute the onclick-function?

Source: AngularJS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.