TypeError:$ http.get(...).then(...).controller不是函数 [英] TypeError: $http.get(...).then(...).controller is not a function
本文介绍了TypeError:$ http.get(...).then(...).controller不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个应用程序,以从AngularJS中的数据库动态加载和显示数据,但是当我尝试使用$ http.get()访问ASP.Net(.ASMX Web服务)时,却收到错误消息:TypeError:$ http.get(...).then(...).controller不是函数请帮助....
I'm building an app to dynamically load and display data from a database in AngularJS, but when I try to access my ASP.Net(.ASMX web service) (using $http.get()), I receive errrors: TypeError: $http.get(...).then(...).controller is not a function Please help....
控制器代码:
.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服务正常运行.
First make sure that your Web service is working properly.
通过以下方式更改您的控制器代码:
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);
})
}]);
未经测试,但应该可以工作.
Not tested, but should work.
这篇关于TypeError:$ http.get(...).then(...).controller不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文