简体   繁体   中英

AngularJS Form two way binding

I'm new to angularJS

i'm try to create a registration form using angularJS

but when i press submit it doesn't work.

The ng-disable attribute is working

HTML

<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 well" ng-contoller="EditUserController">
      <form name="registerUser" class="form">
        <legend>Register</legend>
        <div class="form-group">
          <label for="inputFirstname">First Name :</label>
          <input type="text" name="firstname" id="inputFirstname" class="form-control" value="" required  title="" placeholder="First Name" ng-model="user.firstname">
        </div>
        <div class="form-group">
          <label for="inputLastName">Last Name :</label>
          <input type="text" name="lastname" id="inputLastName" class="form-control" value="" required title="" placeholder="Last Name" ng-model="user.lastname">
        </div>
        <div class="form-group">
          <label for="inputUsername">UserName :</label>
          <input type="text" name="username" id="inputUsername" class="form-control" value="" required  title="" placeholder="Username" ng-model="user.username">
        </div>
        <div class="form-group">
          <label for="inputEmail">Email :</label>
          <input type="email" name="email" id="inputEmail" class="form-control" value="" required title="" placeholder="your email" ng-model="user.email">
        </div>
        <button class="btn btn-primary" ng-disabled="registerUser.$invalid" ng-click="saveuser(user,registerUser)" >Submit</button>
      </form>       
</div>

EditUserController.js

motobike.controller('EditUserController',
function EditUserController($scope){
    $scope.saveuser = function(user, register){
        console.log(register);
        if (register.$valid) {
          window.alert('suceess');
        }   
    }
}   
);

app.js

'use strict';
var motobike = angular.module('motobike', ['ngSanitize']);

ng-contoller更改为ng-controller ^^

class="col-xs-8 col-sm-8 col-md-8 col-lg-8 well" ng-contoller="EditUserController"

should be

class="col-xs-8 col-sm-8 col-md-8 col-lg-8 well" ng-controller="EditUserController"

^^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM