/**
* Created with JetBrains WebStorm.
* User: Faizan
* Date: 3/7/14
* Time: 6:09 PM
* To change this template use File | Settings | File Templates.
*/
angular.module("myApp",[])
.controller("CtrlParent",function($scope){
$scope.ParentFunc= function(){
alert("This is Parent");
// $scope.$on("hello");
}
})
.controller('CtrlBigChild',function($scope){
$scope.BigChildFunc= function(){
alert("This is Big Child");
// $scope.$on("hello");
}
})
.controller('CtrlChildOne',function($scope){
$scope.ChildOneFunc= function(){
alert("This is Child One");
// $scope.$on("hello");
}
})
.controller('CtrlChildTwo',function($scope){
$scope.CtrlChildTwoFunc= function(){
alert("This is Child Two");
// $scope.$on("hello");
}
})
.controller('CtrlChildOneChild',function ($scope){
$scope.ChildOneChildFunc= function(){
alert("This is Child one's Child");
// $scope.$on("hello");
}
})
.controller('CtrlChildTwoChild',function($scope){
$scope.ChildTwoChildFunc= function(){
alert("This is Child Two's Child");
// $scope.$on("hello");
}
})
1:无法加载资源文件:/// C:/Users/Faizan/WebstormProjects/AngularJS%20emit%20broadcase%20controller/js/controller.js.js
2:未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.2.10/ $ injector / modulerr?p0 = myApp& p1 =错误%3A%... rJS%2520emit%2520broadcase%2520controller%2Fjs%2Fangular.min.js %3A17%3A431)
答案 0 :(得分:1)
确保您在ng-app中引用了正确的模块
<body ng-app="myApp">
This demo包含您的代码,不会产生任何错误。
您可以通过将ng-app(在小提琴选项下)更改为其他内容来重现错误2:
<body ng-app="banana">
并确保在javascript文件之前引用angular,例如controller.js。