0

我试图让我的表单使用 http post 提交,但是当我填写表单并按下继续按钮时没有任何反应。http 帖子甚至没有在 Chrome 的网络选项卡中触发。有任何想法吗?我的代码如下:

我的角度控制器:

  $routeProvider.when('/member-reg',{
    templateUrl: 'index.php/routers/member_reg',
    controller: 'registerAsMember'
  });
app.factory("memberRegistrationService", function($http, $location) {
  return {
    register: function(member_info) {
      return $http({
            method: 'POST',
            url: 'index.php/home/member_reg',
            data: { member_info: member_info }
      });
    }
  }
});

app.controller('registerAsMember', function($http, $location, $scope, memberRegistrationService) {
      $scope.member_info = { username: "", password: "",
                             firstname: "", lastname: "", email: "" };
      $scope.member_reg_submit = function() {
        memberRegistrationService.register($scope.member_info).success(function(data) {
          if(data.success == true) {
            model('hello world');
          }
        }).error(function(data) {
          alert('error');
        });
      }
 });

我的观点:

<div class="alert alert-block">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <h4>Register as a Member ...</h4>
  Fill out the form below and press continue when finished.
</div>
<form ng-submit="member_reg_submit">
    <label>Key in your desired username below:</label>
    <input autofocus ng-model="memberinfo.username" style="width: 200pt" type="text" placeholder="Username..." required><br>
    <label>Key in your desired password:</label>
    <input ng-model="memberinfo.password" style="width: 200pt" type="password" placeholder="Password..." required><br>
    <label>Enter your firstname:</label>
    <input ng-model="memberinfo.firstname" style="width: 200pt" type="text" placeholder="Firstname..." required><br>
    <label>Type in your lastname below:</label>
    <input ng-model="memberinfo.lastname" style="width: 200pt" type="text" placeholder="Lastname..." required><br>
    <label>Your email address:</label>
    <input ng-model="memberinfo.email" style="width: 200pt" type="text" placeholder="Email..." required><br>
    <button type="submit" class="btn">Continue</button><br><br>
</form>
4

1 回答 1

1

在继续中添加 ng-click="member_reg_submit()"

删除 ng-submit="member_reg_submit"

更新代码:

<form>
<label>Key in your desired username below:</label>
<input autofocus ng-model="memberinfo.username" style="width: 200pt" type="text" placeholder="Username..." required><br>
<label>Key in your desired password:</label>
<input ng-model="memberinfo.password" style="width: 200pt" type="password" placeholder="Password..." required><br>
<label>Enter your firstname:</label>
<input ng-model="memberinfo.firstname" style="width: 200pt" type="text" placeholder="Firstname..." required><br>
<label>Type in your lastname below:</label>
<input ng-model="memberinfo.lastname" style="width: 200pt" type="text" placeholder="Lastname..." required><br>
<label>Your email address:</label>
<input ng-model="memberinfo.email" style="width: 200pt" type="text" placeholder="Email..." required><br>
<button type="submit" class="btn" ng-click="member_reg_submit()" >Continue</button><br><br>

于 2013-09-16T07:10:12.593 回答