angularJS table 만들기

ng-app를 적용할 div 생성

<div ng-app="myApp" ng-controller="customersCtrl"> 

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

</div>

ng-app에 렌더링될 script구문 추가

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
  $http.get("customers.php")
  .then(function (response) {$scope.names = response.data.records;});
});
</script>

전체코드

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

<style>
  table,   th,   td {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
  }

table tr:nth-child(odd) {
background-color: #f1f1f1;
}

table tr:nth-child(even) {
background-color: #ffffff;
}

</style>

<body>

<div ng-app="myApp" ng-controller="customersCtrl">

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

</div>

<script>
  var app = angular.module('myApp', []);
  app.controller('customersCtrl', function($scope, $http) {
      $http.get("https://www.w3schools.com/angular/customers.php")
          .then(function(response) {
              $scope.names = response.data.records;
          });
  });
</script>

</body>
</html>


'angularJS' 카테고리의 다른 글

angularJS CDN  (0) 2018.10.14

홈페이지

https://angularjs.org/


angularJS tutorial

https://www.w3schools.com/angular/default.asp



angularJS CDN

1.6.9 버전

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

1.7.5 버전

https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js


'angularJS' 카테고리의 다른 글

angularJS Table Tutorial  (1) 2018.10.14

+ Recent posts