1

I have two modules tms2 and tms_sub . I need to access mainCtrl inside mCtrl. Is this possible.

Tms

var tms2 = angular.module('tms2', ['tms_sub']);
tms2.controller("mCtrl", ["$scope","$controller", function ($scope,$controller) {
$scope.test = "a1";
$scope.testClick = function () {
   }
}]);

Tms_sub

var tms_sub = angular.module("tms_sub", []);
tms_sub.controller("mainCtrl", ["$scope", function ($scope) {
   $scope.test ="a"
   $scope.testClick1 = function() {
       alert($scope.test);
   }
}]);

How to call the function testClick1() form mainCtrl of tms_sub module inside function testClick(){} in mctrl of tms2 module.

$scope.testClick = function() {
       testClick1()
   }

}

2
  • 2
    See this question: stackoverflow.com/questions/25417162/… Commented Oct 15, 2015 at 11:37
  • Btw follow cheekybastard's answer on the link above instead of the accepted answer. Commented Oct 15, 2015 at 13:19

2 Answers 2

1

Tip: Create separate service for common methods and inject into both controllers.

Sign up to request clarification or add additional context in comments.

Comments

0

Did you tried this:

var tms2 = angular.module('tms2', ['tms_sub']);
tms2.controller("mCtrl", ["$scope","$controller”,"mainCtrl", function ($scope,$controller, mainCtrl) {
$scope.test = "a1";
$scope.testClick = function () {
   }
}]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.