国家变更时如何重置城市价值

时间:2017-05-25 09:37:32

标签: angularjs

这里我使用Angularjs级联dropdownList作为v当我选择国家 - >印度,州 - > Telangana,City ---> Hydrabad.But当我将Country改为India时城市不会重置,直到我不会改变状态

Country,State,City

Angular.js

<b>Country</b>
<select class="form-control" ng-model="Cnt_Id" ng-required="true" ng-options="I.Cnt_Id as I.Cnt_Name for I in countryData" ng-change="GetState()">

</select>
<b>State</b>
<select class="form-control" ng-model="Sts_Id" ng-required="true" ng-options="I.Sts_Id as I.Sts_Name for I in StateData" ng-change="GetCity()">
    <option value="">{{StateVal}}</option>

</select>
<b>City</b>
<select class="form-control" ng-model="City_Id" ng-required="true" ng-options="I.City_Id as I.City_Name for I in CityData">
    <option>Select City</option>
    <option value="">{{CityVal}}</option>
</select>

2 个答案:

答案 0 :(得分:2)

在提取新状态值时清除城市列表

$scope.GetState = function () {
        var StateSer = Myservice.GetstaeService($scope.Cnt_Id)
        StateSer.then(function (d) {
            $scope.StateData = d.data;
            $scope.CityData= [];
        })
    }

答案 1 :(得分:1)

在选择国家时重置州和城市 重置城市选择国家
就是这样

function GetCountry() {
    var CountrySer = Myservice.GetCountryData();
    CountrySer.then(function(d) {
        $scope.countryData = d.data;
        $scope.StateVal = "Please Select Staes";
        $scope.StateData = []; //new line
        $scope.CityVal = "Please Select City"; //new line
        $scope.CityData = []; //new line
    }).then(function(res) {
        console.log('Error....')
    })
}

$scope.GetState = function() {
    var StateSer = Myservice.GetstaeService($scope.Cnt_Id)
    StateSer.then(function(d) {
        $scope.StateData = d.data;
        $scope.CityVal = "Please Select City";
        $scope.CityData = []; //new line
    })
}
$scope.GetCity = function() {
    var Cityser = Myservice.Getcity($scope.Sts_Id);
    Cityser.then(function(d) {
        $scope.CityData = d.data;
    })
}