我在angularjs工厂中有数据是kendo网格的dataSource,我也希望得到原始数据对象来编写一些逻辑,但是我无法将数据对象从工厂填充到控制器,console.log
正在打印工厂里的数据。如何使用相同的angularJS工厂在控制器中获取json对象?
factory.js
angular.module('App').factory('processService', function($http, $stateParams, OrcitLoader) {
'use strict';
getPrcChallengesGridDataSource: function(processKey, challengeType) {
return new kendo.data.DataSource({
type: 'json',
transport: {
read: function(options) {
return OrcitLoader.load($http.get('app/challenge/rest/getChallengesForGrid?key=' + processKey + '&challengeType=' + challengeType)).success(
function(data) {
console.log(data);
options.success(data);
}).error(function(err) {
console.log(err);
});
}
},
});
Controller.js
angular
.module('App')
.controller('ProcessCtrl', function($scope, processService) {
processService.getPrcChallengesGridDataSource($stateParams.processId,challengeTypeLkupCode).then(function(response) {
var data = response.data;
}
});
答案 0 :(得分:1)
从服务中返回数据
angular.module('App').factory('processService', function($http, $stateParams, OrcitLoader) {
'use strict';
getPrcChallengesGridDataSource: function(processKey, challengeType) {
return new kendo.data.DataSource({
type: 'json',
transport: {
read: function(options) {
return OrcitLoader.load($http.get('app/challenge/rest/getChallengesForGrid?key=' + processKey + '&challengeType=' + challengeType)).success(
function(data) {
console.log(data);
options.success(data);
return data
}).error(function(err) {
console.log(err);return;
});
}
},
});