1

I am trying to write a HTML tag

<li ng-repeat="(key, value) in getusermenu">
<a ng-click="ctrl.{{key}}()" ng-href="#!{{key}}">{{value}}</a></li>

. Here I am getting values of key and value successfully. But the problem here is ng-click="ctrl.{{key}}()" is not calling the function. But when I am hardcoding(ng-click="ctrl.functionName1()") the function name it's running fine. The problem here is, angular js is not printing the key if it is in middle. How I can achieve this?

1
  • I have tried ng-click="ctrl.[key]()" Commented Feb 1, 2018 at 11:41

1 Answer 1

2

Use bracket notation to access object property by variable name:

ng-click="ctrl[key]()"
Sign up to request clarification or add additional context in comments.

1 Comment

Good thanks! I was just bracket notation, the problem with me was "dot" ctrl.[key]()

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.