AngularJS - ng-options不填充对象列表

时间:2017-01-23 11:13:46

标签: javascript angularjs json

我试图在AngularJS中填充组合框。以下是控制器代码。

var app = angular.module('app');

app.controller('roadmap', function($rootScope, $scope, $http, $q, leFactory) {
    $rootScope.activityInfoList=[];

    $rootScope.brand_strategy_list=[];
    $rootScope.brand_strategy_csf=[];
    $rootScope.brand_strategy_initiatives=[];

    leFactory.getActivityPopupInfo().then(function(activityList) {
        $rootScope.activityInfoList=angular.copy(activityList);
        console.log($rootScope.activityInfoList);

        $rootScope.brand_strategy_list=$rootScope.activityInfoList.listBrandStrategy;

        console.log($rootScope.brand_strategy_list);

        console.log('editActivityPopup service accepted-> ');
    }, function(error) {
        console.log('editActivityPopup service rejected-> ', error);
    });

    $rootScope.items = [{
      id: 1,
      label: 'aLabel',
      subItem: { name: 'aSubItem' }
    }, {
      id: 2,
      label: 'bLabel',
      subItem: { name: 'bSubItem' }
    }];



});

在HTML部分中,我尝试填充 $ rootScope.brand_strategy_list ,如下所示。

    <select ng-model="activityInfoList.brandStrategy" class="selectpicker" data-style="btn-inverse" style="display: none;"  ng-options="item.strategyName as item.strategyName for item in brand_strategy_list">
        <option> Select </option>
     </select>

$ rootScope.brand_strategy_list 未填充。但是当我尝试填充 $ rootScope.items 时,它就会被填充。我制作了 console.log($ rootScope.brand_strategy_list),并显示了完整列表。

不知道我在做什么错误?请帮我解决这个问题。在此先感谢。

2 个答案:

答案 0 :(得分:0)

试试这个

ng-options="item.strategyName as item.strategyName for item in $root.brand_strategy_list

答案 1 :(得分:0)

删除style =“display:none;”从html并将$ rootScope更改为$ scope

<select ng-model="activityInfoList.brandStrategy" class="selectpicker" data-style="btn-inverse"   ng-options="item.strategyName as item.strategyName for item in brand_strategy_list">
        <option> Select </option>
     </select>