首页 > Web开发 > 详细

AngularJS 指令ng-submit

时间:2015-10-03 14:20:10      阅读:336      评论:0      收藏:0      [点我收藏+]

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

 

<!doctype html>
<html ng-app="myApp">
<head>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>
  
<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>
  
</body>
</html>

 

 

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 指令ng-submit

原文:http://www.cnblogs.com/ByronWu12345/p/4853309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!