我写了下面的控制器,在我的应用程序会从我的数据库并显示信息中:角,运行区间功能,超时
控制器:
.controller('activityCtrl', function($scope, $http, $interval) {
$http.get("user.php")
.then(function (response) {$scope.names = response.data.records;});
})
user.php的
现在我试图修改控制器,以便它运行getData函数并以预定义的时间间隔更新视图,并且Im有一些麻烦,将更新的必要部分与已有的工作。这里是控制器,因为它已被修改:
.controller('activityCtrl', function($scope, $http, $timeout) {
$scope.getData = function(){
$http.get("user.php")
.success(function(data,status,headers,config){
//The next line needs to be modified to work with the new code
//.then(function (response) {$scope.names = response.data.records;});
console.log("data fetched");
});
};
$scope.intervalFunction = function(){
$timeout(function(){
$scope.getData();
$scope.intervalFunction();
}, 1000)
};
$scope.intervalFunction();
});
目前我有console.log运行测试,一切都是功能。我把我的旧代码注释掉了;这是我需要重写的行,以便根据需要显示数据。很感谢任何形式的帮助。
间隔已经工作;我不知道如何重写.success函数,以便显示$ http的结果。
不要尝试创建JSON手动...它是非常耗时且容易出错,并且可以简单地使用'json_encode($阵列)来完成' – charlietfl
'成功'开火吗?你看到'data fetched'消息吗?真的不清楚具体问题是什么 – charlietfl
是的,console.log根据需要进行报告。 – DataGuy