Is there a way to change the method called by ng-click dynamically?
Something like this:
ng-click = "{{functionCalled}}"
and then declaring the function by:
$scope.functionCalled = "callThisFunction(param)";
Is there a way to change the method called by ng-click dynamically? Something like this:
and then declaring the function by:
|
|||
|
From the docs, ngClick just evaluates the expression in the context of the scope. There's nothing stopping you from referencing a function dynamically, but I'm not sure this is the intended method. I would probably call a function explicitly and switch the behavior based on a parameter instead like HTML
JavaScript
|
|||||||||||||||||||||
|
Assuming you have a set list of possible functions, use a central function to dispatch calls to other functions.
Then
Edit: Actually, use a full dispatch table for this: http://designpepper.com/blog/drips/using-dispatch-tables-to-avoid-conditionals-in-javascript |
|||
|