我的AngularJs版本是 v1.4.3
,在做表单验证时,遇到了问题。
我希望达到的效果是:当表单内容为空时,登录按钮禁用。但现在是登录按钮没有被禁用。
<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>
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"); } } }]);
<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.