i have 1 controller think of 'root' controller, 1 declared ng-controller
attribute, few other controllers instantiated dynamically via $routeprovider
. want declare function available via ng-click
attribute in scope of of dynamic/child controllers.
i can declare function on root controller, e.g.
$scope.announce = function () { alert($scope.specificname); }
then see on of scopes 'child' controllers, $scope
used in function local root controller, not active scope/controller. how can access active, child scope in function?
you can pass child scope parameter:
in "root" controller:
$scope.announce = function (childscope) { alert(childscope.specificname); };
in "child" controller:
$scope.announce($scope);
or, since need call function ng-click
:
in "child" controller:
$scope.callannounce = function(){ $scope.announce($scope) };
the advantage here can have same code in child controllers, , have modify function in root controller, should have edit functionality.
Comments
Post a Comment