Your problem is not related to angular, but to Javascript.
var arr = []
You can verify this by running the following code:
var a = [1]; var b = a; a = [2];
However, if you are manipulating a property of an object
var a = { data: 1 } var b = a; a.data = 2;
If you understand this, there are many ways to solve your problem, for example:
angular.module('testApp') .factory('Thing', function($http) { var obj = {}; return { things: obj, get: function() { $http.get('/api/things').success(function(data) { obj.data = data; }); } }; })
And in your HTML use things.data .
Or if you do not want to use the property of the object, but the array itself, instead of replacing the pointer, you only need to update the contents of the array (so that arr still points to the same array):
angular.module('testApp') .factory('Thing', function($http) { var arr= []; return { things: arr, get: function() { $http.get('/api/things').success(function(data) { for (var i in data) { arr[i] = data[i]; } }); } }; })
source share