Angularjs 如何使用angular JS显示基于另一个选择的选择值
我在选择框中有位置列表。选择位置时,应在另一个选择框中显示相应的IncidentTypeAngularjs 如何使用angular JS显示基于另一个选择的选择值,angularjs,Angularjs,我在选择框中有位置列表。选择位置时,应在另一个选择框中显示相应的IncidentType $scope.locationNames=[ {id:"Onboard",value:"On-board service"}, {id:"Clubhouse",value:"Clubhouse"}, {id:"Gate",value:"Gate"} ]; $scope.incidentTypesList={
$scope.locationNames=[
{id:"Onboard",value:"On-board service"},
{id:"Clubhouse",value:"Clubhouse"},
{id:"Gate",value:"Gate"}
];
$scope.incidentTypesList={
Onboard:[
{id:"IFE faulty",value:"IFE faulty"},
{id:"223",value:"No special meal as ordered"},
{id:"Spoilt",value:"Spoilt/damaged belongings"}
];
Clubhouse:[
{id:"",value"No appointments available"},
{id:"",value="Late/delayed transport service"},
{id:"",value="Facilities not available"}
];
};
我可以使用下面的代码获取列表中的位置名称
<select class="firstDropDown" ng-model="location" ng-options="item.id as item.value for item in locationNames">
<option value="">Select location</option>
</select>
选择位置
您能否帮助我如何在此基础上实现选择,以在另一个选择框中显示值。我认为下面的解决方案适合您的需要。数组中存在一些语法错误,需要修复 HTML
<div ng-app="myApp" ng-controller="myAppCtrl">
<select class="firstDropDown" ng-model="location" ng-options="item.id as item.value for item in locationNames">
<option value="">Select location</option>
</select>
<select class="secondDropDown" ng-model="incident" ng-options="incident.id as incident.value for incident in incidentTypesList[location]">
<option value="">Select incident</option>
</select>
</div>
jsidle:ng click=“getIncidentList(location)”不是必需的。谢谢ABr。它解决了我的问题。有些时候,这些小错误会毁掉一整天
var myApp = angular.module("myApp", [])
myApp.controller("myAppCtrl", function($scope){
$scope.locationNames=[
{id:"Onboard",value:"On-board service"},
{id:"Clubhouse",value:"Clubhouse"},
{id:"Gate",value:"Gate"}
];
$scope.incidentTypesList={
Onboard:[
{id:"IFE faulty",value:"IFE faulty"},
{id:"223",value:"No special meal as ordered"},
{id:"Spoilt",value:"Spoilt/damaged belongings"}
],
Clubhouse:[
{id:"",value:"No appointments available"},
{id:"",value:"Late/delayed transport service"},
{id:"",value:"Facilities not available"}
]
}
});