0
내 코드입니다 :서비스 범위를 업데이트하려면 어떻게해야합니까? 여기
angular.module("testApp", [])
.service("testService", function() {
var privateScope = [1,2,3];
return {
getScope: function() {
return privateScope;
},
addToScope:function(num) {
privateScope.push(num);
}
}
})
.controller("testCtrl", ["$scope","testService"], function($scope, testService) {
$scope.tests = testService.getScope();
$scope.current = $scope.tests[0];
$scope.addToScope = testService.addtoScope;
});
보기 :
<div ng-controller="testCtrl">
<div ng-repeat="num in tests">
<div>{{num}}</div>
</div>
<input type="button" ng-click="addToScope(Math.round(Math.random() * 10))" />
</div>
버튼에
윌 클릭 컨트롤러의 범위뿐만 아니라 서비스를 업데이트? 나는 이것을하는 방법에 관해서는 매우 혼란 스럽다.