[英]Angular ng-show select option child options
所以,如果我有這樣的選擇:
<div class="form-group">
<label for="beneSelect">Select your benefit</label>
<select class="form-control" id="beneSelect" >
<option ng-repeat="descr in claim.claimBenes"
data-ng-model="claimInfo.providerName">{{ descr.descr }}</option>
</select>
</div>
並在此之下,如果'descr'具有具有數據的同級屬性,則要ng-show
選擇option
,這樣做的最佳方法或最佳方法是什么?
因此,例如,如果我要提取的JSON數據具有9個不同的屬性,並且在初始選擇中,我將顯示為:
"id": "%2fooTA9gmtHE8IJ13CdcAww%3d%3d",
"planTypeId": 1,
"benefitTypeId": 11,
"benefCode": "LHCFSA",
"descr": "Limited Health Care FSA (1/1/2015 - 12/31/2015)",
"askSecIns": false,
"askResidual": false,
"hasFunds": true,
"startDate": "2015-01-01T00:00:00",
"endDate": "2015-12-31T00:00:00",
"expenseTypes": [
{
"id": 56,
"descr": "General Dental Care"
},
{
"id": 52,
"descr": "General Vision Care"
},
{
"id": 57,
"descr": "Orthodontia"
},
{
"id": 58,
"descr": "Preventive Care"
}
],
如果expenseTypes
“ HAS”數據,則將顯示另一個選擇,否則,將僅顯示一個選擇。 實際上,我將顯示一個帶有HTML的新<div>
和另一個<select>
。
不確定在Angular中解決此問題的最佳方法。 有例子的建議嗎?
非常感謝。
可以將expenseTypes
數組的長度用作布爾值
ng-if="claim.expenseTypes.length"
我想您正在尋找這個...。
也許它將幫助您提出一些想法。
(function() { 'use strict'; function InputController() { var secondary = { A: [1, 2, 3], B: [3, 4, 5] }, vm = this; vm.primary = ['A', 'B']; vm.selectedPrimary = vm.primary[0]; vm.onPrimaryChange = function() { vm.secondary = secondary[vm.selectedPrimary]; }; } angular.module('inputs', []) .controller('InputCtrl', InputController); }());
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script> <div class="container" ng-app="inputs" ng-controller="InputCtrl as ctrl"> <div class="row"> <div class="col-xs-6"> <h3>Primary</h3> <select class="form-control" ng-model="ctrl.selectedPrimary" ng-options="item for item in ctrl.primary" ng-change="ctrl.onPrimaryChange()"></select> </div> <div class="col-xs-6"> <h3>Secondary</h3> <select class="form-control" ng-model="ctrl.selectedSecondary" ng-options="item for item in ctrl.secondary"></select> </div> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.