0
我正在使用Restangular和angularJS。從狀態解析和從控制器調用Restangular的區別
以下是我的控制器代碼。 我無法在控制檯上打印教師輸出,我無法使用vm.teacherList
進行遊戲。
案例1:
angular.module("subjectManagement").controller('subjectTeacherAllocationCtrl',
function ($scope, $state, $location, Restangular) {
var vm = this;
vm.teacherList = Restangular.all("teacher").getList().$object;
console.log(" vm.teacherList ---> " + vm.teacherList);
});
console output is only `vm.teacherList --->`
當我檢查網絡XHR,我能夠與數據的老師迴應像
[{teacherId: "3", empId: "9", teacherDateOfJoining: "2015-11-02", teacherJoiningGrade: "TGT",…},…]
0: {teacherId: "3", empId: "9", teacherDateOfJoining: "2015-11-02", teacherJoiningGrade: "TGT",…}
1: {teacherId: "4", empId: "10", teacherDateOfJoining: "2015-11-02", teacherJoiningGrade: "TGT",…}
案例2: 如果我把相同的代碼行狀態解決而不是控制器。我可以在控制檯上打印vm.teacherList
,我可以用vm.teacherList
做任何事情。
.state('subjectTeacherAllocation', {
url: '/subject/subjectTeacherAllocation',
templateUrl: 'app/subject/edit/subjectTeacherAllocation.html',
controller: 'subjectTeacherAllocationCtrl as vm',
resolve: {
teacher: function (Restangular, $stateParams) {
return Restangular.all('teacher').getList();
}
}
})
angular.module("subjectManagement").controller('subjectTeacherAllocationCtrl',
function ($scope, $state, $location, teacher, Restangular) {
var vm = this;
$scope.teacher = {}
vm.teacherList = teacher.plain();
console.log(" vm.teacherList ---> " + vm.teacherList);
});
console output is only vm.teacherList ---> vm.teacherList ---> [object Object],[object Object],[object Object],[object Object],[object Object]
我想了解的是什麼的情況下,2
我你的消息後檢查,但如果你仍然有問題,寫電流的答案是正確的... –
@PoyrazYilmaz:感謝您抽空看看。 – fresher