25 February 2018

AngularJS: ng-include AngularJS

ng-include
app.js
AngularJS
(function () {
   var app = angular.module('app', []);

   app.controller('ngIncludeDemoCtrl', ngIncludeDemoCtrl);

   ngIncludeDemoCtrl.$inject = ['$scope'];

   function ngIncludeDemoCtrl($scope) {
      var employees = [{
            name: 'Hải',
            birthDate: new Date('12/3/1989'),
            salary: 15000000,
            gender: 'Male',
            status: true
         },
         {
            name: 'Hoàng',
            birthDate: new Date('6/15/1990'),
            salary: 12000000,
            gender: 'Male',
            status: true
         },
         {
            name: 'Long',
            birthDate: new Date('1/14/1992'),
            salary: 17000000,
            gender: 'Male',
            status: false
         },
         {
            name: 'Trung',
            birthDate: new Date('12/3/1993'),
            salary: 12000000,
            gender: 'Male',
            status: true
         },
         {
            name: 'Hương',
            birthDate: new Date('12/3/1995'),
            salary: 11000000,
            gender: 'Female',
            status: false
         },
         {
            name: 'Thủy',
            birthDate: new Date('12/3/1988'),
            salary: 10000000,
            gender: 'Female',
            status: true
         }
      ];
      $scope.employees = employees;
      $scope.employeeView = 'tableEmployeeView.html';
   }

   app.filter('status', function () {
      return function (input) {
         if (input == true)
            return 'Kích hoạt';
         else
            return 'Khóa';
      }
   });
})()
index.html
AngularJS
<!DOCTYPE html>
<html>
   <head>
      <title></title>
      <meta charset="utf-8" />
      <!-- Latest compiled and minified CSS -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
      <!-- Optional theme -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
      <script src="../srcipts/angular.js"></script>
      <script src="/session13/app.js"></script>
   </head>
   <body ng-app="app">
      <div ng-controller="ngIncludeDemoCtrl">
         Select view:
         <select ng-model="employeeView">
            <option value="tableEmployeeView.html">Table</option>
            <option value="listEmployeeView.html">List</option>
         </select>
         <div ng-include="employeeView"></div>
      </div>
   </body>
</html>
listEmployeeView.html
AngularJS
<ul>
   <li ng-repeat="employee in employees">
      {{employee.name}}
   </li>
</ul>
tableEmployeeView.html
AngularJS
<table class="table">
   <tr>
      <td>Name</td>
      <td>Date of Birth</td>
      <td>Salary</td>
      <td>Gender</td>
      <td>Status</td>
   </tr>
   <tr ng-repeat="employee in employees">
      <td>{{employee.name | uppercase}}</td>
      <td>{{employee.birthDate | date:"dd/MM/yyyy"}}</td>
      <td>{{employee.salary | currency:""}}</td>
      <td>{{employee.gender | lowercase}}</td>
      <td>{{employee.status | status}}</td>
   </tr>
</table>
Nguồn TEDU

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang