【问题标题】:Controller chaining in angularJSangularJS中的控制器链接
【发布时间】:2014-03-10 06:25:26
【问题描述】:
/**
 * 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=Error%3A%…rJS%2520emit%2520broadcase%2520controller%2Fjs%2Fangular.min.js%3A17%3A431 )

【问题讨论】:

  • 使用服务器,http://

标签: javascript angularjs controller


【解决方案1】:

确保您在 ng-app 中引用了正确的模块。
<body ng-app="myApp">

This demo 包含您的代码,不会产生任何错误。

您可以通过将 ng-app(在小提琴选项下)更改为其他内容来重现错误 2,例如:
<body ng-app="banana">


并且,请确保在您的 javascript 文件(例如 controller.js)之前引用 angular。

【讨论】:

  • 我已经检查过仍然面临 Uncaught ReferenceError: angular is not defined controller.js:9 Uncaught Error: [$injector:modulerr] errors.angularjs.org/1.2.10/$injector/…...rJS%2520emit%2520broadcase%2520controller%2Fjs%2Fangular。 min.js%3A17%3A431)
  • 对 angular 的引用必须在你的 controller.js 文件之前。
  • 太好了,我在答案中添加了这个建议。
猜你喜欢
  • 2015-07-08
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 2015-09-15
  • 2016-04-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多