简体   繁体   English

ng-hide和ng-show在dropdownlist angularjs上

[英]ng-hide and ng-show on dropdownlist angularjs

i am creating a web app in which i have 4 dropdownlist 我正在创建一个Web应用程序,其中有4个下拉列表

<select>//calling dynamic data</select
<select>//calling dynamic data as per dropdown1</select
<select>//calling dynamic data as per dropdown2</select
<select>//calling dynamic data as per dropdown3</select

i want to make dropdown 2,3,4 uneditable, when user change the text of dropdown1(dropdown2) should be editable and when he change the text of downdown 2(dropdown3) should be visible and so on. 我想使下拉菜单2、3、4不可编辑,当用户更改下拉菜单1(dropdown2)的文本应可编辑,而当他更改下拉菜单2(dropdown3)的文本应可见,依此类推。

needed ur help 需要您的帮助

You need ng-disabled, and enable it upon ng-change event. 您需要禁用ng,并在ng-change事件启用它。 I will explain this with just 2 dropdowns. 我将仅用2个下拉列表进行解释。 you can extend this to as many as you want. 您可以将其扩展到任意数量。

  <select ng-change="fruitselect(fruitname)" ng-model="fruitname" ng-init="fruitname = fruits[0]" >        
    <option ng-repeat="fruit in fruits" value="{{fruit}}">{{fruit}}</option>
   </select>

  <select ng-model="desertname" ng-disabled="isDessertDisabled">        
    <option ng-repeat="dessert in desserts" value="{{dessert}}">{{dessert}}</option>
   </select>

In the 2nd dropdown,note that ng-disabled="isDessertDisabled" . 在第二个下拉列表中,请注意ng-disabled="isDessertDisabled" Now in the angular controller, 现在在角度控制器中

$scope.fruits = ['apple', 'orange','banana', 'grapes', 'plum'];
$scope.isDessertDisabled = true;
$scope.desserts = ['apple pie', 'orange crush', 'red wine', 'plum cake']
$scope.fruitselect = function(fruitname){
  // some http call to get some desserts based on fruit name
  // $scope.desserts = response from $http call
  $scope.isDessertDisabled = false;
} 

Now, although I have hardcoded the desserts array, in your case, it will bepopulated from http call. 现在,尽管我已经对甜点数组进行了硬编码,但在您的情况下,它将从http调用中填充。 And then isDessertDisabled will be set to false . 然后将isDessertDisabled设置为false This will enable the 2nd dropdown with the fetched desserts values 这将使第二个下拉菜单具有获取的甜点值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM