javascript - How to call function of one controller from other controller in angularjs? -
i want call listing function of testcontroller usercontroller. mark(//) place want call function in following code. doing in angularjs
function usercontroller($scope, $http) { $scope.signup = function() { $http.post('<?php echo site_url('angularjs/addtotable'); ?>', {'uname': $scope.username, 'pswd': $scope.userpassword, 'email': $scope.useremail} ).success(function(data, status, headers, config) { // here want call listing function of testcontroller ... }); } } function testcontroller($scope, $http) { $scope.listing = function() { $scope.users = []; $http.get('<?php echo site_url('angularjs/get_list'); ?>').success(function($data) { $scope.users = $data; }); } }
if nest these 2 controllers in markup, can access parent scope functions in child controller. if not, function might not belong controller, service, provider or factory.
<div ng-controller="testcontroller"> <div ng-controller="usercontroller"> </div> </div>
Comments
Post a Comment