I have a factory that is retrieving the data from an external source. As soon as i get the data, i use a second factory to filter it by a certain criteria.
The factory property is assigned to scope.
Now when i do this in my factory, it doesn't update the scope:
factory.foo = [{id:1,name:'foo'}]; // doesn't work
therefor also the filterin in a second factory doesn't work
factory.foo = Filter.filter(); // doesn't work
while this works:
factory.foo.push({id:1,name:'foo'}); // works
Does anyone have an idea if this is intended and why it is like this, and how to solve it?
app.factory('Foo',function(Filter) {
var factory = {
foo:[],
getDataForFoo:function() {
factory.foo = Filter.filter(); // doesn't work
//factory.foo = [{id:1,name:'foo'},{id:1,name:'foo'}]; // doesn't work
//factory.foo.push({id:1,name:'foo'}); // works
}
};
return factory;
});
app.factory('Filter',function() {
var factory = {
filter:function() {
var arr = [];
arr.push({id:1,name:'foo'});
return arr;
}
}
return factory;
});
app.controller('MainCtrl', function($scope,Foo) {
$scope.test = 'running';
$scope.foo = Foo.foo;
$scope.click = Foo.getDataForFoo;
});