Javascript 在AngularJS中将项目添加到价值服务

Javascript 在AngularJS中将项目添加到价值服务,javascript,angularjs,angularjs-service,Javascript,Angularjs,Angularjs Service,我有以下资料: .value('objs', {item1:'some item',item2:'another item'}); 我想在这里添加一些项目。所以我为它创建了一个控制器: .controller('myCtrl',function($scope, objs){ $scope.addToObjs = function(i){ objs.push(i); } $scope.addToObjs({item3:'an

我有以下资料:

.value('objs', {item1:'some item',item2:'another item'});
我想在这里添加一些项目。所以我为它创建了一个控制器:

.controller('myCtrl',function($scope, objs){    
    $scope.addToObjs = function(i){
        objs.push(i);           
    }

    $scope.addToObjs({item3:'and another item'});
});

这不可能吗

您正试图调用对象上的push。尝试这样做:

$scope.addToObjs = function(i){
    angular.extend(objs, i);           
}