gpt4 book ai didi

javascript - AngularJS 表单两种方式绑定(bind)

转载 作者:行者123 更新时间:2023-11-28 15:50:20 24 4
gpt4 key购买 nike

我是 angularJS 新手

我尝试使用 angularJS 创建注册表单

但是当我按提交时它不起作用。

ng-disable 属性正在工作

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 ^^

关于javascript - AngularJS 表单两种方式绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20843823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com