當用戶點擊提交按鈕時,我正在驗證表單,使用ng-click我正在調用函數,在這個函數中我傳遞了form1。$ invalid,根據這個變量,我提出了條件,如果條件爲true,validate函數會調用,這裏的問題是移動的隱藏字段,這個隱藏字段也檢查validation.how可以跳過或不驗證移動字段的隱藏狀態,我嘗試了下面的代碼。如何在ng-click中不驗證隱藏字段?
HTML ----
<form name="form1" novalidate>
<input ng-show="user" type="text" name="user" ng-model="frm1.user" />
<p ng-show="form1.user.$error.required"><span ng-show="errorMsgShow" ng-required="true">{{requiredMsg}}</span></p>
<input ng-show="mobile" type="text" name="mobile" ng-model="frm1.mobile" />
<p ng-show="form1.mobile.$error.required"><span ng-show="errorMsgShow" ng-required="true">{{requiredMsg}}</span></p>
<button ng-click="SubmitForm(regForm.$invalid);">submit</button>
</form>
腳本----
$scope.SubmitForm = function(val){
$scope.user= true;
$scope.mobile = false;
if (if(val ===true){
$scope.validation();
}
}
$scope.validation = function(){
$scope.requiredMsg="input fieldis required";
}
我怎麼能做到這一點,請大家幫我 –
移動領域將只顯示用戶選擇特定的國家,如「美國,英國,印度等明智它會隱藏起來。 –
@ ramesh1226使用ng-if =「mobile」和ng-if =「user」代替ng-show – Jenny