I have two ng-controllers for example controller1, controller2, i want to inject controller2 method in controller1 and i want to access through my JS API function using "document.querySelector('[ng-controller=custom-entity-design-ctrl]')". Is it possible to get? I tried using factory services that also not working. It's saying error $scope not defined.
source code
**controller1**
myApp.controller("controller1",function($scope, $document, $http, $localStorage) {
$scope.test1 = function() {
alert("test1");
};
});
**controller2**
myApp.controller("controller2",function($scope,$http,$compile,$localStorage, $log) {
$scope.test2 = function() {
alert("test2");
};
});
In detail... i want to access $scope.test2 method from controller1.
I tried using factory also not working.
source code:
myApp.factory("testService", function($compile, $http, $scope) {
$scope.test2 = function() {
alert("test2");
};
}
factory injected in controller1
myApp.controller("controller1",['testService',function($scope, $document, $http, $localStorage) {
$scope.test1 = function() {
alert("test1");
};
}]);
Can anyone help me to achieve this.