2 回答

TA貢獻1898條經驗 獲得超8個贊
AngularJS提供$http控制,可以作為一項服務從服務器讀取數據。服務器可以使一個數據庫調用來獲取記錄。 AngularJS需要JSON格式的數據。一旦數據準備好,$http可以用以下面的方式從服務器得到數據。
function studentController($scope,$http) {
var url="data.txt";
$http.get(url).success( function(response) {
$scope.students = response;
});

TA貢獻1846條經驗 獲得超7個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <html> <head> <title>AngularJs Demo</title> <script type='text/javascript' src="./angular.min.js"></script> </head> <body ng-app="myApp"> <h1>AngularJs Demo</h1> <div ng-cloak ng-controller="DemoCtrl" ng-init="pageInit()">{{hello}}</div> <script type='text/javascript'> var app = angular.module('myApp', []); app.controller('DemoCtrl', function($scope) { $scope.pageInit = function() { $scope.hello = 'Hello AngularJs'; } }); </script> </body> </html> |
保存為html, 當前目錄需要angular.min.js文件.
- 2 回答
- 0 關注
- 532 瀏覽
添加回答
舉報