My AngularJs version is v1.4.3
, and I encountered a problem when doing form validation.
The effect I want to achieve is: when the form content is empty, the login button is disabled. But now the login button is not disabled.
<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"); } } }]);
滿天的星座2017-05-15 16:56:24
<input type="text" ng-model="test" required/> <button type="submit" ng-disabled="form.$invalid">提交</button>
我想大声告诉你2017-05-15 16:56:24
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.
我想大声告诉你2017-05-15 16:56:24
<form name="categoryAddBox">
<input type="text" ng-model="preAddCategoryName" required>
<input type="submit" ng-click="addCategory($event)" value="确定" ng-disabled="!categoryAddBox.$valid">
</form>