0

I am reading a Json file and dynamically creating the elements using angular template.I wanted to bind the event to ng-click which is mentioned in the json file,but it throws exception.Kindly help. Thanks in Advance.

 <button id="{{controls.id}}" ng-click='{{controls.onAction}}' title="{{controls.tooltipText}}"
                                        ng-mouseover="mouseOver(this)" ng-mouseout="mouseOut(this)" style="font-size: 70%;
                                        border: none; border-spacing: 1px;" class="button">
                                        <img src="{{controls.imageSrc}}" class="image{{tabBoxes.Type}}" id="Img1" />
                                        {{controls.label}}
                                    </button>
Sankar Rajmen
  • 23
  • 1
  • 7

1 Answers1

0

Create a $scope.onAction() function in the controller, and change ng-click as follows:

ng-click='onAction()'

Update in response to comment:

Since the functions are strings, use eval(), e.g.:

$scope.onAction = eval('(' + functionAsString + ')');

See this answer on SO on how to use eval() in JS.

Community
  • 1
  • 1
Steve Lang
  • 539
  • 4
  • 8
  • Thanks for your reply.But in my application every button has different onaction methods.the function is a string from json and i m trying to map as click function.how to do. – Sankar Rajmen Sep 11 '14 at 05:15
  • 1
    Thanks again the eval is not working for me.but i have found another way to do it. var act = new Function(e.onAction); act(); – Sankar Rajmen Sep 11 '14 at 09:27