AngularJS의 데이터베이스에서 동적으로 데이터를로드하고 표시하는 앱을 빌드하고 있지만 ASP.Net (.ASMX 웹 서비스) ($ http.get () 사용)에 액세스하려고하면 오류가 발생합니다. TypeError : $ http.get (...). then (...). controller는 함수가 아닙니다. 도와주세요 ....
컨트롤러 코드 :
.controller("studentsController", function ($scope, $http ) {
$http.get("StudentService.asmx/GetAllStudents")
.then(function (response) {
$scope.students = response.data;
})
students.html 코드 :
<h1>List of Students</</h1>
<ul>
<li ng-repeat="student in students">
{{student.name}}
</li>
</ul>
먼저 웹 서비스가 제대로 작동하는지 확인하십시오.
다음과 같은 방법으로 컨트롤러 코드를 변경하십시오.
angular.module('myapp')
.controller("studentsController",['$scope', '$http', function (scope, http ) {
http.get("StudentService.asmx/GetAllStudents")
.success(function(data) {
scope.students = data;
})
.error(function(data, status) {
console.error('Response error', status, data);
})
}]);
테스트되지 않았지만 작동해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다