繁体   English   中英

我们如何使用带有JSON模式的angularjs以相同的HTML格式发送和接收数据?

[英]How can we send and receive data in same HTML form using angularjs with JSON schema?

假设是这样的形式:

<form name="inputForm">
 <input type="text" name="ipname" ng-model="formData.name">
 <input type="text" name="ipage" ng-model="formData.age">
 <button ng-submit="formSubmit(formData)"></button>
</form>

我们如何需要使用名称或ng-model编写JSON模式以将其存储在数据库中?

您可以执行以下操作。 在您的版本中,唯一的问题是您正在使用带有按钮的ng-submit ,该按钮应在form级别使用。

 var app = angular.module('test',[]); app.controller('testController',function($scope){ $scope.formData = {} $scope.formSubmit = function() { // Form validations console.log($scope.formData) // Use formData JSON Object to send it to API using $http/$resource } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script> <body ng-app="test" ng-controller="testController"> <form name="inputForm"> <input type="text" name="ipname" ng-model="formData.name"> <input type="text" name="ipage" ng-model="formData.age"> <button ng-click="formSubmit()">Submit</button> </form> </body> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM