首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ng-提交在angularjs中不起作用

ng-提交在angularjs中不起作用
EN

Stack Overflow用户
提问于 2014-02-17 22:24:12
回答 5查看 52K关注 0票数 28

我的观点是:

代码语言:javascript
复制
<div class="modal" tabindex="-1" role="dialog" ng-controller="LocationController">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" ng-click="$hide()">&times;</button>
        <h4 class="modal-title">
          Add a Location
        </h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal" role="form" ng-submit="createLocation()">
          <div class="form-group">
            <label class="col-sm-2 control-label">Name</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" placeholder="Warehouse A, Row 15, Shelf BC1, etc" ng-model="name">
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">Type</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" placeholder="warehouse, row, shelf, etc" ng-model="type">
            </div>
          </div>

        </form>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Save</button>
        <button type="button" class="btn btn-danger" ng-click="$hide()">Cancel</button>
      </div>
    </div>
  </div>
</div>

我的控制器:

代码语言:javascript
复制
angular.module('mean').controller('LocationController', ['$scope', '$location', '$rootScope', 'LocationService', '$modal', '$routeParams', function ($scope, $location, $rootScope, LocationService, $modal, $routeParams) {

  $scope.createLocation = function() {
alert('afds');
    LocationService.create(this).then(function(response) {
      console.log(response);
    });
  }

}]);

然而,当我单击保存时,我没有收到警报。不知道那里发生了什么。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2014-02-17 22:28:33

多亏了Matt Waycomment -原来我的保存按钮在我的表单之外。

票数 43
EN

Stack Overflow用户

发布于 2015-05-28 04:47:43

也许您应该在表单标记上添加'novalidate‘属性,以避免本机浏览器验证,如此处https://docs.angularjs.org/guide/forms所示

票数 7
EN

Stack Overflow用户

发布于 2016-07-07 15:01:26

这也会影响到,表单中必须有一个提交按钮(按钮或输入type=" submit "),否则ng-submit将不起作用。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21831557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档