我有这个问题:在HTML页面中我有两个选择,第二个选择取决于第一个
HTML
FIRST
<select class="trip dark" ng-model="formSearch.selectedRegione" ng-options="regione.nome for regione in regioni.regionSelector">
<option value="">TUTTE</option>
</select>
SECOND
<select class="trip dark" ng-model="formSearch.selectProvincia" ng-options="provincia.nome for provincia in formSearch.selectedRegione.province">
<option value="">TUTTE</option>
</select>
问题是,当我从我的控制器中获取选定值时,它会返回第一个对象并且未定义&#39;对于第二个,而不是我期望的价值。
修改
所有两个选项都可以正常工作,这意味着当我在第一个选择中选择一个值时,第二个选择了正确的值。
我的问题是在我的控制器中我这样做了
var selectedRegione= $scope.formSearch.selectedRegione;
var selectedProvincia= $scope.formSearch.selectedProvincia;
selectedRegione返回对象,selectedProvincia返回undefined
修改
HTML
<div ng-controller="mainController">
<div class="holder">
<select class="trip dark" ng-model="formSearch.selectedRegione" ng-
options="regione.nome for regione in regioni.regionSelector">
<option value="">TUTTE</option>
</select>
</div>
<div class="holder">
<select class="trip dark" ng-model="formSearch.selectProvincia" ng-
options="provincia.nome for provincia in formSearch.selectedRegione.province">
<option value="">TUTTE</option>
</select>
</div>
<button class="btn btn-trip" ng-click="ricercaAttivita()">Ricerca</button>
<div>
CONTROLLER
var tantoSvagoApp = angular.module('tantoSvagoApp', ['ui.bootstrap', 'ui-rangeSlider']);
tantoSvagoApp.controller("mainController", function ($scope, serviceRegioni,
srvShareData, $location, $window) {
$scope.ricercaAttivita = function() {
var selectedRegione= $scope.formSearch.selectedRegione;
var selectedProvincia= $scope.formSearch.selectedProvincia;
console.log("selectedRegione " + selectedRegione );
console.log("selectedProvincia " + selectedProvincia );
}
});
对象中的selectedRegione,未定义的selectedProvincia