izle. Basit bir değişken çalışıyor, ancak bir nesne işe yaramıyor. http://plnkr.co/edit/S4b2g3baS7dwQt3t8XEK?p=previewangularjs hizmet nesnesi
var app = angular.module('plunker', []);
app.service('test', ['$http', '$rootScope',
function ($http, $rootScope) {
var data = 0;
var obj = {
"data": 0
};
this.add = function(){
obj.data += 1;
console.log('data:', obj);
};
this.getData = function() { return obj; };
}]);
app.controller('TestController', ['$scope', '$rootScope', '$filter', 'test',
function($scope, $rootScope, $filter, test) {
//test controller
$scope.add = function(){
test.add();
};
$scope.test = test;
$scope.$watch('test.getData()', function(newVal){
console.log('data changes into: ', newVal)
});
}]);
olası yinelenen [$ açısal bir nesneyi izlemek] (http://stackoverflow.com/questions/19455501/watch-an-object -in-açısal) – kvetis
size() { dönüş test.getData() 'işlevi yazmak göstermektedir; }, 'yerine 'test.getData()'. Böylelikle hatalardan kaçınabilirsiniz, çünkü açısal dize tanımını doğrulamaz. –