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里面的代码为什么不会每加载一次页面都运行一次?
慕容森
相关分类