我收到服務中的數據,但我收到的數據爲未定義。我的AngularJS服務返回數據,但我收到未定義。AngularJS服務延遲發送數據
我的服務代碼:
myApp.service("studentinfo", function ($http) {
var studentlist = [];
this.GetStudentList = function() {
$.getJSON("/Home/GetStudentsList", function (data) {
if (data.Result == "OK") {
studentlist = data.Data;
}
else {
studentlist = [];
}
}).complete(function() {
return studentlist;
});
};
});
我的控制器代碼:
myApp.controller("studentcontroller", function ($scope, $http, studentinfo) {
$scope.StudentList = [];
function LoadStudentRecord(){
$scope.StudentList = studentinfo.GetStudentList();
}
LoadStudentRecord();
});
我得到的數據正確..我想我直接調用contoller(studentinfo.GetStudentList();)中的方法並收到輸入是問題... – Vicky 2015-02-10 10:04:39