天天看点

Controller中错误 TypeError: $rootScope.$broadcast is not a function

最近研究Angluar的前端开发,遇到

TypeError: $rootScope.$broadcast is not a function 错误!

代码:

...
myApp.controller('queryCtrl',['$scope','$document','$rootScope',function($scope,$rootScope){
    $scope.queryClick = function(){
           var url = "http://localhost:8080/DataVisualor/ServletJson?"+
          "TID="+tID+"&"+
          "TOwner="+tOwner+"&"+
          "TNumber="+carNumber+"&"+
          "TStartTime="+tStartTime+"&"+
          "TEndTime=" + tEndTime ;
        $rootScope.$broadcast('update',url);
}]);
           

错误原因:

'$document','$rootScope'

顺序需要互换,不然,function中$rootScope对应到$document 类型了,没有 $rootScope.$broadcast方法。