0

I have got a problem with calling a controller(not just a function) from another controller. My HTML looks like:

<div ng-app="MyApp">
  <div ng-controller="MyCtrl">
  <div id="msg"></div>
  </div>
</div>

And the script:

var module = angular.module('MyApp', []);

module.controller('MyCtrl', [function() {
    angular.element(document).ready(function () {
        test();
    });
}]);

module.controller('test', [function() {
    document.getElementById('msg').innerHTML = 'Hello';
}]);

Please see the jsfiddle here: http://jsfiddle.net/y35emhny/

Is there any way how I can achieve it?

qqruza
  • 1,385
  • 4
  • 20
  • 41
  • 3
    Well, to start with you haven't included your test controller in your dom, how do you expect it to be loaded? Secondly, controllers don't exchange values directly, you use a service for that. There's tons of examples online, and here on SO as well, http://stackoverflow.com/questions/9293423/can-one-controller-call-another?rq=1 for instance – Patrick Nov 12 '15 at 16:42
  • 1
    Please refer to : http://stackoverflow.com/questions/9293423/can-one-controller-call-another – Airwind711 Nov 12 '15 at 16:45

0 Answers0