我有一张要使用ng-repeat
. 我无法弄清楚如何格式化我的数组以使其正常工作。这是我到目前为止所拥有的:
PHP(客户.php):
$customer_array = array();
$customer1 = array(
'customer_id' => '1',
'name' => 'John Doe',
'city' => 'New York'
);
$customer_array[] = $customer1;
$customer2 = array(
'customer_id' => '2',
'name' => 'Jane Doe',
'city' => 'Boston'
);
$customer_array[] = $customer2;
echo($customer_array);
AngularJS 控制器(CustomersCtrl.js):
$http({
url: 'customers.php',
method: "POST"
})
.success(function (data, status) {
$scope.customers = data;
})
.error(function (data, status) {
$scope.status = status;
});
HTML:
<table>
<tbody ng-controller="CustomersCtrl">
<tr ng-repeat="customer in customers">
<td>{{customer.customer_id}}</td>
<td>{{customer.name}}</td>
<td>{{customer.city}}</td>
</tr>
</tbody>
</table>
这是行不通的。我究竟做错了什么?
更新:我想知道这是否是因为我使用下面的代码从上面加载 HTML 代码:
$routeProvider.when('/customers.php', {
templateUrl: 'partials/customers.html',
controller: 'CustomersCtrl'
});
ng-repeat
是不是因为新加载的 html 模板在尝试循环之前没有绑定到控制器?