本文實例講述了Angular.JS讀取數據庫數據調用。分享給大家供大家參考,具體如下:
以下是實例代碼:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <style> table{position:relative;} table, th , td { border: 1px solid grey; border-collapse: collapse; padding: 10px 20px; } table tr:nth-child(odd) { background-color: #f1f1f1; } table tr:nth-child(even) { background-color: #ffffff; } i{display:block;background:url(buffer.gif) no-repeat;position:absolute;left:50%;margin-left:-16px;top:50px;width:32px;height:32px;} </style> </head> <body> <center style="margin-top:100px;"> <div ng-app="myApp" ng-controller="customersCtrl"> <h3>數據統計</h3> <table> <tr> <th>活動編號</th> <th>活動名稱</th> <th>點擊量</th> <th>最后訪問時間<i id="buffer"></i></th> <th>所屬欄目</th> </tr> <tr ng-repeat="x in names"> <td>{{ x.sid }} </td> <!--活動編號--> <td>{{ x.sname }} </td> <!--活動名稱--> <td>{{ x.sclick }} 次</td> <!--點擊量--> <td>{{ x.stime | date:'yyyy-MM-dd HH:mm:ss' }}</td> <!--最后訪問時間--> <td>{{ x.sproject }}</td> <!--所屬欄目--> </tr> </table> </div> </center> <script> var buffer = document.getElementById("buffer"); buffer.style.display = 'block'; var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) { $http.get("Customers_MySQL.php") .success(function (response) { $scope.names = response; buffer.style.display = 'none'; //成功調取數據之后 }); //成功調取mysql數據,將response.records改為response,因為它是個對象 }); </script> </body> </html>
更多關于AngularJS相關內容可查看本站專題:《AngularJS指令操作技巧總結》、《AngularJS入門與進階教程》及《AngularJS MVC架構總結》
希望本文所述對大家AngularJS程序設計有所幫助。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com