我有一张表格
<form role="form" name="signup" novalidate>
<div class="form-group" ng-class="{ 'has-error' : signup.firstname.$invalid && !signup.firstname.$pristine }">
<label>First Name</label>
<input type="text" name="firstname" class="form-control" ng-model="firstname" required>
<p ng-show="signup.firstname.$invalid && !signup.firstname.$pristine" class="help-block">You name is required.</p>
</div><div class="form-group"">
<label>Last Name</label>
<input type="text" name="lastname" class="form-control" ng-model="lastname">
</div>
<div class="form-group" ng-class="{ 'has-error' : signup.phone.$invalid && !signup.phone.$pristine }">
<label>Phone</label>
<input type="text" name="phone" class="form-control" ng-model="phone" ng-minlength="10">
<p ng-show="signup.phone.$invalid && !signup.phone.$pristine" class="help-block">Number is too short!!</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : signup.email.$invalid && !signup.email.$pristine }">
<label>Email</label>
<input type="email" name="email" class="form-control" ng-model="email">
<p ng-show="signup.email.$invalid && !signup.email.$pristine" class="help-block">Enter a valid email.</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : signup.password.$invalid && !signup.password.$pristine }">
<label>Password</label>
<input type="password" name="password" class="form-control" ng-model="password" ng-minlength="6">
<p ng-show="signup.password.$invalid && !signup.password.$pristine" class="help-block">Password is too short</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : signup.passwordRepeat.$invalid && !signup.passwordRepeat.$pristine }">
<label>Password Repeat</label>
<input type="password" name="passwordRepeat" class="form-control" ng-model="passwordRepeat" ng-minlength="6">
<p ng-show="signup.passwordRepeat.$invalid && !signup.passwordRepeat.$pristine" class="help-block">Password repeat is too short</p>
</div>
<button type="submit" class="btn btn-primary btn-success" ng-disabled="signup.$invalid" ng-click="signing()">Create New Account</button>
</form>
它调用控制器函数signing()
$scope.signing = function () { $scope.signup($scope.firstname, $scope.lastname, $scope.email, $scope.telephone, $scope.password, $scope.$passwordRepeat); }
反过来调用
$scope.signup = function ($firstname, $lastname, $email, $phone, $password, $passwordRepeat) {....}
但控制台正在说
事实是,这两个函数都是在同一个控制器中定义的,并且工作正常,之前,我似乎无法解决可能出错的问题。 它开始说有一个错误,我试图做表单验证。 任何帮助将受到高度赞赏。“错误:$ scope.signup不是函数”
答案 0 :(得分:0)
问题是您对表单使用相同的名称:name="signup"
。这也在signup
中创建$scope
属性,覆盖您在控制器中定义的signup
函数。改变其中一个应该工作。