簡體   English   中英

角形不提交

[英]Angular form doesn't submit

我有這個角度腳本

var app = angular.module('j_app', ['ngMaterial'], function($interpolateProvider)    {
    $interpolateProvider.startSymbol('<%');
    $interpolateProvider.endSymbol('%>');
});

app.controller('j_controller', function($scope, $http) {
  $scope.formdata = {};

  $scope.formsubmit = function(){
    $http({
       method : 'POST',
       url : '/dodong',
       data : $.param($scope.formdata),
       headers : {'Content-Type' : 'application/x-www-form-urlencoded'}
    }).success(function(data){
       console.log(data); 
    });
  };
});

這個角形

<body ng-app="j_app">
<div ng-controller="j_controller">
<form ng-submit="formsubmit()">
    <fieldset>
        <input type="text" name="username" ng-model="formdata.username" placeholder="Your username here..." />
        <input type="password" name="password" ng-model="formdata.password" placeholder="Your password here..." />
    </fieldset>
    <button>Submit test angular</button>
</form>
</div>
</body>

但是表單沒有提交,卻什么也沒有發生,也沒有拋出任何錯誤。 有任何想法嗎?

如果在“ Plunker”中鍵入此命令,它將起作用:

<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
</head>

<body ng-app="submitTest">
  <script>
    angular.module('submitTest', [])
      .controller('j_controller', ['$scope', function($scope) {
        $scope.text = 'type something, will ya';
        $scope.formsubmit = function() {
          alert("Called");
        };
      }]);
  </script>
  <div ng-controller="j_controller">
    <form ng-submit="formsubmit()">
      <fieldset>
        <input type="text" ng-model="text" name="text" />
      </fieldset>
      <input type="submit" id="submit" value="Submit" /> </form>
  </div>
</body>

</html>

您需要使用<input type="submit">

我猜測應該刪除此線程,因為AngModel的V6中已棄用了ngModel。 在V7中將被完全刪除

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM