javascript - Controller chaining in angularJS -
/** * created jetbrains webstorm. * user: faizan * date: 3/7/14 * time: 6:09 pm * change template use file | settings | file templates. */ angular.module("myapp",[]) .controller("ctrlparent",function($scope){ $scope.parentfunc= function(){ alert("this parent"); // $scope.$on("hello"); } }) .controller('ctrlbigchild',function($scope){ $scope.bigchildfunc= function(){ alert("this big child"); // $scope.$on("hello"); } }) .controller('ctrlchildone',function($scope){ $scope.childonefunc= function(){ alert("this child one"); // $scope.$on("hello"); } }) .controller('ctrlchildtwo',function($scope){ $scope.ctrlchildtwofunc= function(){ alert("this child two"); // $scope.$on("hello"); } }) .controller('ctrlchildonechild',function ($scope){ $scope.childonechildfunc= function(){ alert("this child one's child"); // $scope.$on("hello"); } }) .controller('ctrlchildtwochild',function($scope){ $scope.childtwochildfunc= function(){ alert("this child two's child"); // $scope.$on("hello"); } })
1: failed load resource file:///c:/users/faizan/webstormprojects/angularjs%20emit%20broadcase%20controller/js/controller.js.js
2 :uncaught error: [$injector:modulerr] http://errors.angularjs.org/1.2.10/$injector/modulerr?p0=myapp&p1=error%3a%…rjs%2520emit%2520broadcase%2520controller%2fjs%2fangular.min.js%3a17%3a431)
make sure referencing correct module in ng-app.
<body ng-app="myapp">
this demo contains code, , produces no errors.
you can reproduce error 2 changing ng-app (under fiddle options) else like:
<body ng-app="banana">
and, make sure reference angular before javascript filess, such controller.js.
Comments
Post a Comment