2017.07.27 12:14

반복된 데이터(배열)를 UI에 표시해 줄 때 사용


// index.html

<!DOCTYPE html>

<html ng-app="web">


<head>

  <script data-require="angular.js@1.6.2" data-semver="1.6.2" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.js"></script>

  <link rel="stylesheet" href="style.css" />

  <script src="controller.js"></script>

</head>


<body ng-controller="WebController">

  <h1>student info</h1>

  

  <!-- ng-repeat="변수 in 변수배열" 처럼 사용 -->

  <ul ng-repeat="Student in Students">

    <li><input type="text" ng-model="Student.Name"/></li>

    <li>Grade: {{Student.Grade}}</li>

    <li>Gender: {{Student.Gender}}</li>

  </ul>

</body>


</html>


// controller.js

// Code goes here


(function() {

  var app = angular.module('web', []);

  

  app.controller("WebController", ["$scope", function($scope) {

    //배열로 선언

    $scope.Students = [

      {Name: "Tom", Grade: 8, Gender: "Male"}, 

      {Name: "Alice", Grade: 10, Gender: "Female"}, 

      {Name: "Ann", Grade: 7, Gender: "Female"}, 

      {Name: "Brown", Grade: 8, Gender: "Male"}, 

    ]

  }])

})();


샘플

Posted by CoolDragon

댓글을 달아 주세요