我有以下模板文件:
<h1>{{title}}</h1>
<ul>
<li ng-repeat="friend in friends">
<input type="text" ng-model="friend.name">
<input type="text" ng-model="friend.gender">
</li>
</ul>
<button ng-click="save()" class="btn btn-primary">Save</button>
我有相应的控制器文件:
angular
.module('app')
.controller('homeCtrl', ['$scope', 'friends', '$http', function($scope, friends, $http) {
$scope.title = "Home";
$scope.friends = friends;
$scope.save = function(){
$http.put('http://localhost:8000/ip', friends)
(JSON.stringify($scope.friends));
};
}]);
http://localhost:8000/ip/_id, jsondata
这样的事情:<button ng-click="save(friend._id)" ng-model="friend._id" class="btn btn-primary">Save</button>
在控制器中就像这样:$http.put('http://westeros:9000/ip/:_id', friends)
答案 0 :(得分:2)
HTML:
<h1>{{title}}</h1>
<ul>
<li ng-repeat="friend in friends">
<input type="text" ng-model="friend.name">
<input type="text" ng-model="friend.gender">
<button ng-click="save(friend)" class="btn btn-primary">Save</button>
</li>
</ul>
JS:
angular
.module('app')
.controller('homeCtrl', ['$scope', 'friends', '$http', function($scope, friends, $http) {
$scope.title = "Home";
$scope.friends = friends;
$scope.save = function(friend){
$http.put('http://localhost:8000/ip/'+ friend.id, friend )
};
}]);