default ngOptions on parent/child models AngularJS

前端 未结 1 1154
甜味超标
甜味超标 2021-01-03 16:36

How do I assign default ngOptions through parent/child models?

In this question OP shows a way form parent/child relationships using <

1条回答
  •  春和景丽
    2021-01-03 17:06

    The blank item is caused by the empty model value. You can try to put the following code at the end of the controller. The trick is to initialize site, building and floor when the page is loaded as well as when the site value is changed. Hope it helps.

    $scope.selected = {
        site: $scope.data[0],
        building: $scope.data[0].buildings[0],
        floor: $scope.data[0].floors[0]
    };
    
    $scope.$watch('selected.site', function () {
        console.log($scope.selected.site);
        $scope.selected = {
            site: $scope.selected.site,
            building: $scope.selected.site.buildings[0],
            floor: $scope.selected.site.floors[0]
        };
    });
    

    0 讨论(0)
提交回复
热议问题