冰我有一個觀點:打破角
<div id="productList" ng-controller="ProductController">
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th width="100%">Item ID</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in productItems">
<td><input type="checkbox" /></td>
<td><% item.ID %></td>
</tr>
</tbody>
</table>
</div>
我有一個控制器:
var TestApp = angular.module('TestApp', [], function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
});
TestApp.controller('ProductController', function ($scope) {
ProductRepository.GetPaginatedProducts();
$scope.productItems = ProductRepository.Model;
});
我有一個模型:
var ProductRepository = function()
{
return {
Model: null,
GetPaginatedProducts: function()
{
$.ajax({
"url": Test.URL + "/json/products/paginated",
"dataType": "json",
"method": "post",
"success": function(data)
{
ProductRepository.Model = data;
}
});
},
}
}
當AJAX完成後,它更新我想讓角控制器scope.productItems工作的ProductRepository.Model數據變量。
這是我第一次使用的角度,我想我已經錯過了點,
爲什麼表中沒有與信息更新?
不要使用jQuery的AJAX在角應用程序,使用提供'$ http'或'$ resource'模塊。 – tymeJV 2014-11-14 15:37:37
它不會更新,因爲AJAX調用發生在角度範圍之外,因此就像@tymeJV使用內置函數一樣,獲取範圍中的數據以觸發將更新視圖的摘要循環。 – 2014-11-14 15:50:02