Please help! I am pulling my hair out over this. I've tried a lot of tutorials for this and can't seem to get anything to work even remotely.
Users can add/delete/update user information on a page, and I want it to refresh whenever they do one of those actions. All of the actions write to the DB just fine and I have had various success with getting the values back out, but I cannot get the view to update in real-time.
I can't use $scope.$apply(); $digest already in process. I feel like there is just some major key I'm missing.
Service
angular.module('userlistFactory', [])
.service('Data', function($http){
this.list = function(){
return $http.get('.../getUsers.php', {cache: true})
.then(function(data){
return data.data;
});
}
Controller
userlistControllers.controller('UserListCtrl', ['$scope', 'Data', function ($scope, Data){
Data.list().then(function (data) { // Populates the page the first time through
$scope.users = data;
})
$scope.$watch('Data.list()', function(newValue){ // At this point, I don't understand
$scope.users = newValue;
}, true);
View
<tr ng-repeat-start="user in users| filter:query | orderBy:'id'">
<td><a href="#/profile/{{user.id}}">{{user.id}}</a></td>
<td>{{user.firstname}}</td> // etc...
Thanks for reading.
$scope.$watch('Data.list()'? How do you know that data is inserted/updated?