表单未在AngularJS中验证

时间:2016-06-13 10:29:23

标签: javascript angularjs validation ng-messages

我有这个简单的形式:

//Dont forget to find your CoolapsingLayout first :)

//set The custom text
mCollapisngToolbar.setTitle("TEXTTTs");

//Set the color of collapsed toolbar text
mCollapisngToolbar.setCollapsedTitleTextColor(ContextCompat.getColor(this, R.color.White));

//This will set Expanded text to transparent so it wount overlap the content of the toolbar          
mCollapisngToolbar.setExpandedTitleColor(ContextCompat.getColor(this, R.color.Transparent));

没有经过验证! <form name="assignCtrl.carrierForm"> <md-input-container class="md-block"> <label>Company Name</label> <input required name="carrierName" ng-model="assignCtrl.searchKeyword"> <div ng-messages="assignCtrl.carrierForm.carrierName.$error"> <div ng-message="required">This field is required.</div> </div> </md-input-container> <md-input-container class="md-block"> <label>Company Email</label> <input type="email" name="carrierEmail" ng-model="assignCtrl.companyEmail" required ng-pattern="/^.+@.+\..+$/" minlength="5" maxlength="100"/> <div ng-messages="assignCtrl.carrierForm.carrierEmail.$error"> <div ng-message="required">Email is required.</div> <div ng-message-exp="['pattern', 'minlength', 'maxlength']">Please enter a valid email address. </div> </div> </md-input-container> <md-button type="submit" ng-disabled="assignCtrl.carrierForm.$invalid" ng-click="assignCtrl.createAndAssign()">Create and Assign </md-button> </form> 根本没有出现。

ng-messages也是空的:

form.$error

可能是什么原因?

1 个答案:

答案 0 :(得分:1)

所以,我发现了我的错误!在我庞大的html文件中,问题中的表单错误地出现在另一个form内!这就是为什么,内部形式被删除!所以,我删除了外形,一切都很好!