用angular写的一个单页面应用为什么切换页面不会自动发送请求刷新页面数据呢?必须点一下刷新才可以更新页面数据?
App.controller("index2", ['$scope', '$http', '$rootScope' function($scope, $http, $rootScope){
$http({
url: "/ot.php",
method: 'get'
}).success(function(data){
$rootScope.loaded = true;
var data = JSON.parse(data);
$scope.data = data.data;
})
}]);
App.config(["$routeProvider", function($routeProvider){
$routeProvider.when('/index', {
templateUrl: './list.html',
controller: 'index'
})
.when('/contai', {
controller: 'index2',
templateUrl: './list2.html'
})
.when('/donnn', {
templateUrl: './demo3.html',
})
.otherwise({
templateUrl: './demo4.html',
});
}])
切换到list2 后,不会自动请求index2控制器的$http,需要点击一下刷新后才会刷新页面数据
已经解决了 用$http就可以了 之前用的jq的$.ajax