1. 程式人生 > >Angular.js入門

Angular.js入門

一、引入angular.js

     <script type="text/javascript" src="../plugins/angularjs/angular.min.js"></script>

二、定義控制器、模組

    

<script type="text/javascript">
        var app = angular.module('eshop',[]);
        app.controller('brandController',function($scope,$http){
            //獲取查詢資料
$scope.findAll= function(){ $http.get('../brand/getAllBrand.do').success( function(res){ $scope.list = res; } ) } }); </script>

三、在body標籤中引入變數

<body class
="hold-transition skin-red sidebar-mini" ng-app="eshop" ng-controller="brandController" ng-init="findAll()">

四、在對應的列表中顯示

                                  <tbody>
                                      <tr ng-repeat="entity in list">
                                          <td><input  type="checkbox" ></td>                                          
                                          <td>{{entity.id}}</td>
                                          <td>{{entity.name}}</td>                                         
                                          <td>{{entity.firstChar}}</td>                                         
                                          <td class
="text-center"> <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" >修改</button> </td> </tr> </tbody>