我在angularjs中实现两个下拉列表。第一个下拉列表列出了所有国家。第二个州的下拉只会显示在美国和加拿大。
状态下拉列表完美地列出了各州,但我没有得到范围内的州下拉值。
代码:
<select ng-if="ProfSettingForm.CountryId.$modelValue == 6" ng-model="StateProv" class="form-control option" ng-init="States = <?php echo htmlspecialchars($allUSStates); ?>"/>
<option value="">Choose Your State</option>
<option ng-repeat="state in States" ng-selected="{{state.StateId == StateId}}"
value="{{ state.StateId }}">{{state.StateName}}
</option>
</select>
<select ng-if="ProfSettingForm.CountryId.$modelValue == 7" ng-model="StateProv" class="form-control option" ng-init="States = <?php echo htmlspecialchars($allCanProvinces); ?>"/>
<option value="">Choose Your Province</option>
<option ng-repeat="state in States" ng-selected="{{state.StateId == StateId}}"
value="{{ state.StateId }}">{{state.StateName}}
</option>
</select>
<h3>{{"Value="+ProfSettingForm.StateProv.$modelValue}}</h3>
AngularJS控制器:
app.controller("profileSettingCTRL", ['$scope', '$http', '$window', function ($scope, $http, $window) {
getAllCountries($scope, $http);
$scope.profileSettingSubmit = function (isValid) {
$scope.successMessage = "";
$scope.message = "";
$scope.myThumb = $window.imagepath;
var data = $.param({
FirstName: $scope.FirstName,
LastName: $scope.LastName,
Email: $scope.Email,
CountryId: $scope.CountryId,
StateProv: $scope.StateProv,
DOB: $scope.DOB,
PictureURL: $scope.myThumb
});
});
答案 0 :(得分:0)
在控制器中获取范围变量$ scope.selectvalue.value并将其应用于ng-model之类 您将在$ scope.selectvalue.value
中获得选定的值