我在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
    });
});

最佳答案

在控制器中获取范围变量$ scope.selectvalue.value并将其应用于ng-model

您将在$ scope.selectvalue.value中获得选定的值

关于javascript - 从Angularjs的辅助下拉列表中获取值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28315010/

10-12 12:35
查看更多