Ajax in AngularJS
AngularJS provides a $ http control that acts as a service to read data from the server. The server can create calls to the database to receive the logs. AngularJS needs data in JSON format.
AngularJS provides a $ http control that acts as a service to read data from the server. The server can create calls to the database to receive the logs. AngularJS needs data in JSON format. When data is available, $ http can be used to receive data from the server in the following way:
function sinhvienController ( $scope , $http ) { var url = "dulieuSV.txt" ; $http . get ( url ). success ( function ( response ) { $scope . sinhvienk60 = response ; }); }
Here the dulieuSV.txt file contains records of students. $ http service creates an ajax call and retrieves the result returned to the student object. " born " model can be used to draw tables with HTML.
Examples:
dulieuSV.txt
[ { "HovaTen" : "Tran Minh Chinh" , "MSSV" : 20150456 , "Diemthi" : "8.0" }, { "HovaTen" : "Nguyen Thi Chinh" , "MSSV" : 20150457 , "Diemthi" : "9.0" }, { "HovaTen" : "Ha Kieu Linh" , "MSSV" : 20150458 , "Diemthi" : "8.5" }, { "HovaTen" : "Ho Ngoc Ha" , "MSSV" : 20150459 , "Diemthi" : "9.5" } ]
viduAJAX.html
Vi du AJAX trong AngularJS
Ung dung AngularJSng-app = "" ng-controller = "sinhvienController" > Ho va Ten MSSV Diem thing-repeat = "sinhvien in sinhvienk60" > {{ sinhvien.HovaTen }} {{ sinhvien.MSSV }} {{ sinhvien.Diemthi }}