您的位置:首页 > Web前端 > AngularJS

ng-submit

2016-04-10 21:02 573 查看
ng-submit用来将表达式同onsubmit事件进行绑定。这个指令同时会阻止默认行为(发送请求并重新加载页面),除非表单不含有action属性。

<form ng-submit="submit()"
ng-controller="FormController">

Enter text and hit enter:
<input type="text"

ng-model="person.name"

name="person.name" />
<input type="submit"

name="person.name"

value="Submit" />
<code>people={{people}}</code>
<ul ng-repeat="(index, object) in people">

<li>{{ object.name }}</li>
</ul>

</form>

angular.module('myApp',[])
.controller('FormController',function($scope) {

$scope.person = {
name: null

};

$scope.people = [];

$scope.submit = function() {
if ($scope.person.name) {

$scope.people.push({name: $scope.person.name});

$scope.person.name = '';
}

};}); 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  angularjs