如果在angularjs中选择默认值,如何将默认值设置为该字段并禁用其他字段 [英] How to set default value to the field and disable other fields if default value is selected in angularjs
问题描述
我有以下字段 - 国家,州,城市,中心。
所有字段的默认值是全部。
我可以通过使用先前字段值的选择逐个启用字段。
但它不考虑全部作为一种价值。如果它认为那么这个国家正在被激活。所以任何人都可以请帮助我如何将默认值设置为全部到所有字段,如果选择全部,则应该关闭其他字段并将全部视为值。
我的HTML页面:
< div class =col- sm-2 sidenavstyle =height:850px;>
< div class =well>
< form class =form-rowrole =form>
< div class =form-group>
<! - <选项值类别选择> ALL< / option> - >
< option ng-repeat =model.countries中的项目跟踪$ indexvalue ={{item}}> {{item}}< / option>
< / select>
< / div>
< div class =form-group>
<! - <选项值类别选择> ALL< / option> - >
< option ng-repeat =model.states中的item跟踪$ indexvalue ={{item}}> {{item}}< / option>
< / select>
< / div>
< div class =form-group>
< label class =control-label col-sm-20for =fName> City *< / label>
<! - <选项值类别选择> ALL< / option> - >
< option ng-repeat =model.cities中的项目跟踪$ indexvalue ={{item}}> {{item}}< / option>
< / select>
< / div>
< div class =form-group>
<! - <选项值类别选择> ALL< / option> - >
< option ng-repeat =model.centers track中的item跟踪$ indexvalue ={{item}}> {{item}}< / option>
< / select>
< / div>
< div class =form-group>
< label class =control-label col-sm-20for =fName>角色*< / label>
<! - <选项值类别选择> ALL< / option> - >
< option ng-repeat =model.roles中的项目跟踪$ indexvalue ={{item}}> {{item}}< / option>
< / select>
< / div>
< div class =form-group>
< button type =submithref =#ng-click =HeadCount()class =btn btn-primary btn-lgng-hide =submitButtonng-disabled =! model.selectedRole> SUBMIT< /按钮>
< / div>
< / form>
< / div>
< / div>
您好,请检查 https://plnkr.co/edit/4Vc5EG7BXKikKGp0EdKe
默认选择
p> $ scope.CategoryLst = [
{id:'0',name:'ALL'},
{id:'1',name:'MD'},
{id:'2',name:'CRNA'},
];
$ scope.item = $ scope.CategoryLst [0]
HTML
< select ng-model =itemng-options =i.name for我在CategoryLstng-change =citychange()>< / select>
onchange禁用了其他选择字段,您可以根据ID或名称检查
$ scope.citychange = function()
{
if($ scope.item.id ==0)
{
$ scope.disabledflag = true
};
}
I have the following fields- country, state, city, center.
The default value for all the fields is "All".
I am able to enable the fields one by one by using selection of previous field value.
But it is not considering "All" as a value. If it considers then the state is getting activated. So can anyone please help me how to set default value as "All" to all the fields and if "All" is selected then the other fields should be disabled with considering "All" as a value.
My HTML Page :
<div class="col-sm-2 sidenav" style="height:850px;">
<div class="well">
<form class="form-row " role="form">
<div class="form-group">
<label class="control-label col-sm-14" for="fName">Country*</label>
<select class="form-control" ng-model="model.selectedCountry" name="country" ng-change="GetCountry(model.selectedCountry)">
<!--<option value class selected>ALL</option>-->
<option ng-repeat="item in model.countries track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
<div class="form-group">
<label class="control-label col-sm-20" for="fName">State*</label>
<select class="form-control" ng-model="model.selectedState" name="state" ng-change="GetState(model.selectedState)" ng-disabled="!model.selectedCountry">
<!--<option value class selected>ALL</option>-->
<option ng-repeat="item in model.states track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
<div class="form-group">
<label class="control-label col-sm-20" for="fName">City*</label>
<select class="form-control" ng-model="model.selectedCity" name="city" ng-change="GetCity(model.selectedCity)" ng-disabled="!model.selectedState">
<!--<option value class selected>ALL</option>-->
<option ng-repeat="item in model.cities track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
<div class="form-group">
<label class="control-label col-sm-20" for="fName">Center*</label>
<select class="form-control" ng-model="model.selectedCenter" name="center" ng-change="GetCenter(model.selectedCenter)" ng-disabled="!model.selectedCity">
<!--<option value class selected>ALL</option>-->
<option ng-repeat="item in model.centers track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
<div class="form-group">
<label class="control-label col-sm-20" for="fName">Role*</label>
<select class="form-control" ng-model="model.selectedRole" name="city" ng-change="GetRole(model.selectedRole)" ng-disabled="!model.selectedCountry">
<!--<option value class selected>ALL</option>-->
<option ng-repeat="item in model.roles track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
<div class="form-group">
<button type="submit" href="#" ng-click="HeadCount()" class="btn btn-primary btn-lg" ng-hide="submitButton" ng-disabled="!model.selectedRole">SUBMIT</button>
</div>
</form>
</div>
</div>
Hi check this https://plnkr.co/edit/4Vc5EG7BXKikKGp0EdKe
for default selection
$scope.CategoryLst = [
{ id: '0', name: 'ALL' },
{ id: '1', name: 'MD' },
{ id: '2', name: 'CRNA' },
];
$scope.item =$scope.CategoryLst[0]
HTML
<select ng-model="item" ng-options="i.name for i in CategoryLst" ng-change="citychange()" ></select>
while onchange disabled the other select filed you can check based on id or Name
$scope.citychange = function()
{
if($scope.item.id == "0")
{
$scope.disabledflag = true
};
}
这篇关于如果在angularjs中选择默认值,如何将默认值设置为该字段并禁用其他字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!