javascript - How to call a scope function based on an attribute value -
i have several 'save , close' links in app, each button has unique function run when clicked, defined directive ng-really-click
. directive confirms closing, runs close function, e.g.
<a ng-really-click="someclosefunction(p1, p2)" />
now elsewhere in app, want 'pretend' user has clicked save button, bypass confirmation. @ given moment, don't know close function should called, , have find out finding close link , inspecting ng-really-click
attribute.
once have function call expression defined in attribute, call function against scope have in variable currentscope
. how can this?
i gueess angularish way use different controllers per link. then, have scope , rootscope pointers ng-really-click function. i.e:
cntrl1:
$scope.funcpointer = $rootscope.funcpointer = function() {console.log('yo1');}
cntrl2:
$scope.funcpointer = $rootscope.funcpointer = function() {console.log('yo2');}
on views, use func pointer:
<div ng-controller="cntrl1"><a ng-really-click="funcpointer(p1, p2)" /></div>
and anywhere in app, execute function rootscope:
from ctrl:
$rootscope.funcpointer(val1, val2);
Comments
Post a Comment