![](/img/trans.png)
[英]angular.js: How to put data from JSON to template and the result into main website?
[英]Angular.js: How to http put a unique id and json data to REST API?
我有以下模板文件:
<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)
的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 )
};
}]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.