如何将响应分配给变量或$ scope。在这里,我想将响应分配给数据变量
'use strict';
`var dashModule = angular.module("Student");`
dashModule.controller("studentDashboardCtrl",
['$scope', 'authService', 'StudentService',
function ($scope, authService, StudentService) {
//Check authorised user
var data;
authService.checAuthentication();
StudentService.getBatchList(function (response) {
console.log(response);
});
}]);
答案 0 :(得分:0)
您可以将其存储在$ scope变量
中答案 1 :(得分:0)
var dashModule = angular.module("Student");
dashModule.controller("studentDashboardCtrl",
['$scope', 'authService', 'StudentService',
function ($scope, authService, StudentService) {
//Check authorised user
var data =[];
authService.checAuthentication();
StudentService.getBatchList(function (response) {
console.log(response);
data.push.response; //just like that you can store the response
});
}]);
答案 2 :(得分:0)
实际上我正在使用console.log()检查结果;但它始终显示未定义。虽然我的方法是对的。我仍然感到困惑,为什么console.log()显示未定义。但视图正确显示了该值。这是代码
'use strict';
var dashModule = angular.module("Student");
dashModule.controller("studentDashboardCtrl",
['$scope', 'authService', 'StudentService',
function ($scope, authService, StudentService) {
//Check authorised user
var names;
authService.checAuthentication();
StudentService.getBatchList(function (response) {
$scope.names = response;
});
console.log($scope.names);
}]);
答案 3 :(得分:-1)
你应该使用它。
ANSI Escape in Console
答案 4 :(得分:-1)
var Module = angular.module("Student");
dashModule.controller("studentDashboardCtrl",
['$scope', 'authService', 'StudentService',
function ($scope, authService, StudentService) {
//Check authorised user
var self = this;
authService.checAuthentication();
StudentService.getBatchList(function (response) {
console.log(response);
self.data = response.data;
});
}]);