Javascript 使用填充的数组don'动态创建下拉列表;t使用角度更新

Javascript 使用填充的数组don'动态创建下拉列表;t使用角度更新,javascript,arrays,angularjs,cascadingdropdown,dropdownbox,Javascript,Arrays,Angularjs,Cascadingdropdown,Dropdownbox,我的第一个下拉列表在页面加载时正确加载,但子下拉列表在本地存储的第一个下拉列表之后加载。问题是,当我加载第二个下拉列表并为其指定默认值时,我无法再更改其值 请为ng show更改ng,第二个下拉菜单将起作用 angular.module('demoApp', []).controller('DemoController', function($scope) { //my first drop down loads with the page $scope.options = [

我的第一个下拉列表在页面加载时正确加载,但子下拉列表在本地存储的第一个下拉列表之后加载。问题是,当我加载第二个下拉列表并为其指定默认值时,我无法再更改其值


请为ng show更改ng,第二个下拉菜单将起作用

angular.module('demoApp', []).controller('DemoController', function($scope) {
  //my first drop down loads with the page
  $scope.options = [
     { label: 'one', value: 1 },
     { label: 'two', value: 2 },
     { label: 'three', value: 3 },
     { label: 'four', value: 4 },
     { label: 'five', value: 5 }
  ];  

  $scope.firstSelect = $scope.options[3];  

//the second drop down loads after the first makes a selection. In the real code I am     populating the second from localstorage, but once it's assigned its default value I cannot change it.    
var init = function(){
   //depends on what was selected in first select
    $scope.captions = [
       { name: 'A', value: 'a' },
       { name: 'B', value: 'b' },
       { name: 'C', value: 'c' },
       { name: 'D', value: 'd' },
       { name: 'E', value: 'e' }
   ]; 
    $scope.secondSelect = $scope.captions[1];
}   
init();

});
<body ng-app="demoApp">
    <div ng-controller="DemoController">

        <div>

            <select ng-model="firstSelect"
                ng-options="opt as opt.label for opt in options">
            </select>
<br><br>
            <select  ng-show="firstSelect.value == '4'" ng-model="secondSelect"
                ng-options="opt as opt.name for opt in captions">
            </select><br>
            The first select value is {{ firstSelect.value }}<br>
            Why can't I get the second select value to update: {{ secondSelect.value }}
        </div>

    </div>
</body>
<body ng-app="demoApp">
    <div ng-controller="DemoController">
        <div>
            <select ng-model="firstSelect" ng-options="opt as opt.label for opt in options"></select>
            <br>
            <br>
            <select ng-if="firstSelect.value == '4'" ng-model="secondSelect.select" ng-options="opt as opt.name for opt in captions"></select>
            <br>The first select value is {{ firstSelect.value }}
            <br>Why can't I get the second select value to update: {{ secondSelect.select.value }}</div>
    </div>
</body>
angular.module('demoApp', []).controller('DemoController', function ($scope) {
    //my first drop down loads with the page
    $scope.options = [{
        label: 'one',
        value: 1
    }, {
        label: 'two',
        value: 2
    }, {
        label: 'three',
        value: 3
    }, {
        label: 'four',
        value: 4
    }, {
        label: 'five',
        value: 5
    }];
    $scope.firstSelect = $scope.options[3];

    //the second drop down loads after the first makes a selection. In the real code I am populating the second from localstorage, but once it's assigned its default value I cannot change it.    
    var init = function () {
        //depends on what was selected in first select
        $scope.captions = [{
            name: 'A',
            value: 'a'
        }, {
            name: 'B',
            value: 'b'
        }, {
            name: 'C',
            value: 'c'
        }, {
            name: 'D',
            value: 'd'
        }, {
            name: 'E',
            value: 'e'
        }];
        $scope.secondSelect = {};
        $scope.secondSelect.select = $scope.captions[1];
    }
    init();

});