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:

<tablegrid
  table="flavorings"
  additional-buttons="[{name: 'add', onclick: 'function(){ }', icon: 'fa fa-plus'}]"
  show-actionbutton="true"
  show-rating="true"
  show-search="true"
  show-rowcheckbox="true"
  show-header="true">
</tablegrid>

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_'+aB.name | uppercase | translate }}</span>
</button>

How can I execute the onclick-function?

Source: AngularJS

Leave a Reply

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