2017-09-24 75 views
0

在我的主页上我有一个选择列表,但我无法弄清楚为什么没有从模型中填充数据。选择列表应该包含产品类别。angularjs选择没有从模型中填充的选项

这里是我的HTML:

<select 
    ng-options="c.name for c in search.productCategories track by c.id" 
    ng-model="search.selectedProductCategory"> 
</select> 

我有一个基本的控制器上我的HTML的身体:

<body ng-controller="baseCtrl"> 

我使用$routeProvider像这样:

$routeProvider 
    .when("/", { 
     templateUrl: "app/views/home.html", 
     controller: "home", 
     resolve: { 
      productCategories: productCategoriesResolver 
     } 
    }) 
... 
... 

我controller looks看起来这样:

function home($scope, productCategories) { 
    ... 
    ... 
    $scope.search.productCategories = productCategories; 
} 

解析器功能:

function productCategoriesResolver(productCategoryService) { 
    return productCategoryService.getProductCategories().then(function(categories) { 
     return categories; 
    }); 
} 

我检查和$scope.search.productCategories填充了类似的措施。

[{id: 1, name: 'Cat-A'}, {id: 2, name: 'Cat-B'}, ...] 

我想也许这是什么做的巢式控制器,但我已经重现的工作嵌套控制器solution

我试过包装$apply,但已经有一个消化周期正在进行中,也试过$timeout,但没有运气。

回答

0

我认为这是因为你的ng选项。尝试是这样的:

<select 
    ng-options="c as c.name for c in search.productCategories track by c.id" 
    ng-model="search.selectedProductCategory"> 
</select> 
+0

同样的问题......它与我在问题中提供的codepen链接中的原始语法一起工作。 – PeteGO

+0

控制台中有任何错误吗? – lingthe

+0

这里是与routerprovider plunker:https://plnkr.co/edit/lXlZfhHYKfduWHew861O?p=preview其中选择显示。不知道你的情况是什么导致了这种行为。 – lingthe

0

我有一个旧的参考bootstrap-select.js这是冲突和导致问题。