angular.js - AngularJS 表单验证
phpcn_u1582
phpcn_u1582 2017-05-15 16:54:24
0
3
487

我的AngularJs版本是 v1.4.3,在做表单验证时,遇到了问题。
我希望达到的效果是:当表单内容为空时,登录按钮禁用。但现在是登录按钮没有被禁用。

-- HTML --

<button class="btn btn-block btn-success" disabled="disabled" name="sign" ng-click="vm.submit(sign_form)" ng-disabled="sign_form.$invalid" type="submit">登 录</button>

-- AngularJS --

var app=angular.module("ayApp",[]);
app.controller("ayAppCtrl",['$scope',function($scope){
    var vm=$scope.vm={};
    vm.d=storedb('ay').find();
    vm.submit=function(sign_form){
        sign_form.$setDirty();
        if(sign_form.$valid){
            alert("Success");
        }
    }
}]);
phpcn_u1582
phpcn_u1582

reply all(3)
滿天的星座

<input type="text" ng-model="test" required/> <button type="submit" ng-disabled="form.$invalid">提交</button>

我想大声告诉你

A vm object is bound to the scope, and then you create a vm. What do you want to do?
Secondly, I don’t think you need to write a controller yourself to implement this function.

我想大声告诉你
    <form name="categoryAddBox">
      <input type="text" ng-model="preAddCategoryName" required>
      <input type="submit" ng-click="addCategory($event)" value="确定" ng-disabled="!categoryAddBox.$valid">
    </form>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!