0
<form class="form-inline" name="form" novalidate>
<div class="sub-form" ng-form is-active ng-init="active = true" name="info">
<div class="col-md-4 col-sm-6 col-ie-4">
<div class="select-input">
<label for="xyz">Xyz *</label>
<i class="fa fa-check-circle success" ng-show="form.info.xyz.$valid"></i>
<i class="fa fa-spinner fa-spin"></i>
<i class="fa fa-times-circle error" ng-show="(form.info.xyz.$invalid && !form.info.xyz.$pristine)"></i>
<div class="styled-select">
<select
heights
name="xyz"
id="xyz"
ng-options="xyz.in as xyz.ft for xyz in xyzs"
ng-model="player.xyz"
required>
<option value="" selected="selected">-- Select --</option>
</select>
</div>
</div>
</div>
</div>
</form>
<div class="back-next-button-row">
<div class="red-button tiny-button next-button" ng-if="form.$valid">
<button ng-click="next()"><span class="button-text">Next</span><i class="fa fa-chevron-right"></i></button>
</div>
<div class="red-button tiny-button next-button" ng-if="form.$invalid">
<button ng-click="error()"><span class="button-text">Error</span><i class="fa fa-chevron-right"></i></button>
</div>
</div><!--back-next-button-row-->
In Script
$scope.form = {};
$scope.form.info = {};
$scope.formError = function() {
console.log($scope.form.info.xyz);
//Getting Object {}
}
雖然在HTML的顯示,我希望 基本上,我想檢查 合適的對象,如果($ scope.form.info.xyz。$無效){ 警報(「Invlid」) }
如果我才知道這是爲什麼在這個前景產生問題
有在控制器進行,由於在點擊一些validtion –
理想的方式是使該按鈕時,形式是有效的,所以你不必攜帶任何東西到控制器。這些是我們必須使用的特殊材料。你可以添加ng-disable =「form. $ invalid」,這將禁用按鈕,所以用戶無法點擊直到其有效 – CrazyMac
但是如果我必須檢查console.log($ scope [form] .info.xyz。 $無效);如果這不正確,它應該返回true。 –