I have a table that I want to populate using ng-repeat
. I'm having trouble figuring out how to format my array so that it works. Here is what I have so far:
PHP (customers.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 Controller (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>
This isn't working. What am I doing wrong?
UPDATE: I'm wondering if this is because I'm loading the HTML code from above using the code below:
$routeProvider.when('/customers.php', {
templateUrl: 'partials/customers.html',
controller: 'CustomersCtrl'
});
Is it because the newly loaded html template is not bound to the controller before it tries to do the ng-repeat
loop?