2 回答

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

TA貢獻(xiàn)1836條經(jīng)驗 獲得超5個贊
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, 當(dāng)前目錄需要angular.min.js文件.
添加回答
舉報