我有使用ng-options
填充2點選擇的形式,如:ngOptions用新值成功刷新,但NG-模型不是數據綁定
<select ng-options="item.id as product.category for product in products" ng-model="order.category" ng-change='find_brands(order.category)' ></select>
<select ng-options="brand.id as brand.name for brand in brands" ng-model="order.brand" ></select>
<button ng-click='Get_Products(order)>ORDER</button>
當選擇所述第一下拉時,會觸發一個$http
打電話來填充第二個下拉像這樣:
$scope.find_brands = function(category){
$http
.get('Default.aspx/Find_Brands', {category: category})
.success(data){$scope.products = data.d};
};
這正確地填充"brands"
下拉使用新值。但是,當我去選擇品牌時,ng-model
不會改變。測試時,我收到一個空值。我已經看着$scope.$apply
與$digest
週期一起工作,但它似乎不是我的問題("brands"
下拉菜單成功刷新數據,它只是不發送數據)。
有沒有人有什麼想法和如何解決它?
我認爲這是你的問題中的一個錯誤,在你的服務中將'data.d'分配給'$ scope.product'。另外,'成功'已棄用'then',所以你可能會考慮使用它。 –
您可以填充類別和品牌的產品。我猜測你正處於某種循環中,因爲如果類別不存在(爲什麼不填充品牌)ng-change會再次被調用,並且可以在單擊訂單按鈕 –