AngularJS는 $ http 컨트롤을 제공하여 서버의 서비스로서 데이터를 읽을 수 있습니다. 서버는 데이터베이스를 호출하여 레코드를 얻을 수 있습니다. AngularJS에는 JSON 형식의 데이터가 필요합니다. 데이터가 준비되면 $ HTTP는 다음 방식으로 서버에서 데이터를 얻을 수 있습니다.
함수 StudentController ($ scope, $ http) {var url = "data.txt"; $ http.get (url) .success (함수 (응답) {$ scope.students = response;});}여기서는 학생 기록이 data.txt에 포함되어 있습니다. $ http 서비스를 통해 Ajax는 학생들을위한 부동산을 전화하고 설정할 수 있습니다. "학생"모델은 HTML 테이블을 그리는 데 사용될 수 있습니다.
예
data.txt
[{ "name": "Mahesh Parashar", "Rollno": 101, "백분율": "80%"}, { "name": "dinkar kad", "rollno": 201, "백분율": "70%"}, { "이름": "Robert", "Rollno": 191, "75%"}, { "" ""}}}} Joe ","Rollno ": 111,"백분율 ":"77%"}]testangularjs.html
<html> <head> <title> Angular JS는 </title> <style> 테이블, TH, TD {테두리 : 1px Solid Grey; 국경-콜라스 : 붕괴; 패딩 : 5px;} 테이블 tr : nth-Child (홀수) {배경 색 : #f2f2f2;} 테이블 tr : nth-child (균일) {배경 색 : #ffffff;} </style> </head> <h2> angularjs 샘플 응용 프로그램 </h2> <div ng-app = <table> <th> name </th> <th> roll no </th> <th> 백분율 </th> </tr> <tr ng-repeat = "학생들의 학생"> <td> {{whient.name}} </td> <td> {{wichake </td> {{{{}}}}}} </tr> </table> </div> <cript> 함수 StudentController ($ scope, $ http) {var url = "data.txt"; $ http.get (url) .success (function (function) {$ scope.students = response;});} </script> <script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> </html산출
이 예제를 실행하려면 TextAngularjs.html, data.txt를 웹 서버에 배포해야합니다. URL을 사용하여 웹 브라우저에서 TextAngularjs.html 요청 서버를 엽니 다. 결과는 다음과 같습니다.
위는 AngularJs Ajax의 기본 정보 분류입니다. 우리는 앞으로 관련 정보를 계속 정리할 것입니다. 이 웹 사이트를 지원 해주셔서 감사합니다!