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>
1
  • Better you paste code here..as we are not mind readers Commented Sep 11, 2014 at 4:21

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.