我有使用angular在json中输出数据的表单,没有数据库。现在无论该表单的输出是什么,我想将它发送到某个服务器这里是代码说我想将它发送到服务器192.80.36.4例如。如何使用帖子
controller definition code
<body ng-app="submitExample">
<script>
angular.module('submitExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.list = [];
$scope.text = '';
$scope.submit = function() {
if ($scope.text) {
$scope.list.push(this.text);
$scope.text = '';
}
};
}]);
</script>
</script>
<form ng-submit="submit()" ng-controller="ExampleController">
Enter latitude:
<input type="text" ng-model="text" name="text" />
<input type="submit" id="submit" value="Submit" />
<pre>list={{list| json}}</pre>
</form>
答案 0 :(得分:3)
您需要使用$http
服务:
angular.module('submitExample', [])
.controller('ExampleController', ['$scope', '$http', function($scope, $http) {
$scope.list = [];
$scope.text = '';
$scope.submit = function() {
if ($scope.text) {
$scope.list.push(this.text);
$scope.text = '';
$http.post("<your-url>", $scope.list).success(function(data, status) {
console.log(data);
})
}
};
}]);