Reputation: 7113
I have data in angularjs factory that is dataSource for kendo grid , i also want to get raw data object to write some logic but i am not able to populate data object from the factory to controller,console.log
is printing the data in factory. How can i get json object in controller using same angularJS factory ?
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;
}
});
Upvotes: 0
Views: 356
Reputation: 18435
Return data from service
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;
});
}
},
});
Upvotes: 1