我正在构建一个应用程序以动态地从AngularJS中的数据库加载和显示数据,但是当我尝试使用$ http.get()访问ASP.Net(.ASMX Web服务)时,出现了以下错误: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>
首先,请确保您的Web服务正常运行。
通过以下方式更改您的控制器代码:
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] 删除。
我来说两句