angularjs ng-repeat

  • 707
  • 0

foreach寫法

<script src="~/Scripts/ngcontroller.js"></script>
<div ng-app="myModule">
    <div ng-controller="myController">
        <table>
            <thead>
                <tr><th>FirstName</th><th>LastName</th><th>Gender</th><th>Salary</th></tr>
            </thead>
            <tbody>
                <tr ng-repeat="employee in employees"  >
                    <td>{{employee.FirstName}}</td>
                    <td>
                        {{employee.LastName}}
                    </td>
                    <td>{{employee.Gender}}</td>
                    <td>{{employee.Salary}}</td>
                </tr>
            </tbody>
        </table>

    </div>

</div>
 

ngcontroller.js

var myApp = angular.module("myModule", []);

myApp.controller("myController", function ($scope) {

    var employees = [{ FirstName: "Charles", LastName: "Chiang", Gender: "Male", Salary: 50000 },
        { FirstName: "Bill", LastName: "Wang", Gender: "Male", Salary: 60000 },
        { FirstName: "Jim", LastName: "Huang", Gender: "FeMale", Salary: 70000 }
    ];
        
    

    $scope.employees = employees;
});