Variable index of Angular

0

asked by anonymous 07.06.2016 / 15:39

1 answer

0

Dude you're doing it wrong, do not use php code in the middle of the Angular. You will have to get the data from the database and return it in JSON format, usually this request is made by REST.

Here's an example:

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://www.w3schools.com/angular/customers.php")
    .then(function (response) {$scope.names = response.data.records;});
});
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script><body><divng-app="myApp" ng-controller="customersCtrl"> 

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country }}</td>
  </tr>
</table>

</div>
</body>
</html>

Example link w3schools

    
07.06.2016 / 15:57