var app = angular.module('gzmu', ["ngRoute",'chart.js']);app.run(function ($rootScope, $http) { $http({ method: 'GET', url: 'datacon/user_info.php', }).success(function (response) { $rootScope.userinfo = response[0]; console.log($rootScope.userinfo) $rootScope.$broadcast("userinfo", response[0]); })});app.controller('data', function ($scope, $http, $rootScope) { $scope.usernamea=''; $scope.$on("userinfo", function (event, msg) { console.log(msg); if(msg){ $scope.usernamea = msg.user; console.log($scope.usernamea) alert($scope.usernamea) } else{ alert(msg) } });});如題,on里面的代碼為什么不會每加載一次頁面都運行一次?
angular中使用了broadcast和on,為什么on里面的代碼不是每次都成功運行?
慕勒3428872
2018-08-28 09:47:27