angular2中怎么請求數據
angular2中怎么請求數據
慕無忌1623718
2019-05-25 15:15:14
TA貢獻1802條經驗 獲得超4個贊
AngularJS提供$http控制,可以作為一項服務從服務器讀取數據。服務器可以使一個數據庫調用來獲取記錄。 AngularJS需要JSON格式的數據。一旦數據準備好,$http可以用以下面的方式從服務器得到數據。
function studentController($scope,$http) {
var url="data.txt";
$http.get(url).success( function(response) {
$scope.students = response;
});
舉報