I have written the following controller that gets info from my DB and displays in in my app:
Controller:
.controller('activityCtrl', function($scope, $http, $interval) {
$http.get("user.php")
.then(function (response) {$scope.names = response.data.records;});
})
user.php
<?php
//DB stuff goes here
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"Regid":"' . $rs["Regid"] . '",';
$outp .= '"Fname":"' . $rs["fname"] . '",';
$outp .= '"Lname":"' . $rs["lname"] . '",';
$outp .= '"activity":"' . $rs["activity"] . '",';
$outp .= '"ID":"'. $rs["id"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$conn->close();
//echo($outp);
?>
Now Im trying to modify the controller so it runs getData function and updates the view at a predefined interval and Im having some trouble incorporating the necessary portions for the update with what I already have working. here is the controller as it has been modified:
.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();
});
Currently I have the console.log running for testing and everything is functional. I have my older line of code commented out; this is the line I need to rewrite in order to display the data as needed. Any help is very much appreciated.
The interval is working already; I dont know how to rewrite the .success function so it displays the results from the $http.