我需要显示/隐藏输入字段的工具提示状态:“这是必填字段”。我正在使用ng-required输入标签。
<form novalidate name="CustAddressDetails">
<input type="text" name="txtResAddressLine1" id="txtResidentialAddress1" ng-model="Address1" ng-required="true" />
<span ng-show="ShowAddressErrorMsg && CustAddressDetails.txtResAddressLine1.$error.required">Please enter the Residential Address.</span>
</form>
&#13;
答案 0 :(得分:1)
此处我已删除ShowAddressErrorMsg
,因为一旦您的表单有效,您需要手动更改
var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testCtrl">
<form name="CustAddressDetails">
<input type="text" name="txtResAddressLine1" id="txtResidentialAddress1" required ng-model="Address1" />
<span ng-show="CustAddressDetails.txtResAddressLine1.$pristine ||
CustAddressDetails.txtResAddressLine1.$untouched ||
(CustAddressDetails.txtResAddressLine1.$touched ||
CustAddressDetails.txtResAddressLine1.$invalid)">Please enter the Residential Address.</span>
<input type="submit"/>
</form>
</div>