angularjs - Make a dynamic function on ng-click -
i have button this
<button ng-click="method = 'create'; title = 'create'>create</button> <button ng-click="method = 'update'; title = 'update'>update</button>
and this
<button ng-click="create(param)">{{ title }}</button> <button ng-click="update(param)">{{ title }}</button>
code above works fine, want make dynamic.
so change following.
<button ng-click="{{ method }}(param)">{{ title }}</button>
this not work, dont know why, although if inspect element, code above generates corrects code mentioned before.
use of bracket notation:
<button ng-click="this[method](param)">{{ title }}</button>
this
points current scope object this[method]
can access method via variable name.
Comments
Post a Comment