一直试图在表单提交上使用角度js获取表单的值。 有人帮我做什么。我是角度JS的新手。
<div id="content" ng-app="TryApp" ng-controller="AppController" ng- submit="submit()">
<input type="text" placeholder="first name" name='name' ng- model="user.Name"/>
<br>
<input type="text" placeholder="email address" name="name" ng-model="user.email"/>
<br>
<input type="text" placeholder="age" name="age" ng-model="user.age"/>
<br>
脚本。
App.controller('AppController', function ($scope){
)}
答案 0 :(得分:7)
var app = angular.module('TryApp', [], function() {})
app.controller('AppController', function($scope) {
$scope.user = {};
$scope.submit = function() {
//here $scope.user will have all the 3 properties
alert(JSON.stringify($scope.user));
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div id="content" ng-app="TryApp" ng-controller="AppController">
<form ng-submit="submit()">
<input type="text" placeholder="first name" name='name' ng-model="user.Name" />
<br>
<input type="text" placeholder="email address" name="name" ng-model="user.email" />
<br>
<input type="text" placeholder="age" name="age" ng-model="user.age" />
<br>
<input type="submit" value="Save" />
<p>{{user | json }}</p>
</form>
</div>
注意:要使提交处理程序正常工作,您需要一个表单和一个提交按钮,如上所示