在我的主頁上我有一個選擇列表,但我無法弄清楚爲什麼沒有從模型中填充數據。選擇列表應該包含產品類別。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
,但沒有運氣。
同樣的問題......它與我在問題中提供的codepen鏈接中的原始語法一起工作。 – PeteGO
控制檯中有任何錯誤嗎? – lingthe
這裏是與routerprovider plunker:https://plnkr.co/edit/lXlZfhHYKfduWHew861O?p=preview其中選擇顯示。不知道你的情況是什麼導致了這種行爲。 – lingthe