Use an AngularJS Service in place of the url in KendoUI Scheduler
I've passed all day long trying to figure out while using a kendoui scheduler adapter for AngularJS the events were not loaded successfully and I found that the reason was the Service's call to get data; replacing it with the URL it correctly works, but it seems so ugly to me. Is there a way I can use it and have things working?
Here's the code I use
angular.module('xxx.controllers').controller('CalendarioController', [
'$scope', '$rootScope', '$mdDialog', '$mdToast', 'CalendarioService',
function ($scope, $rootScope, $mdDialog, $mdToast, CalendarioService) {
var self = this;
self.scope = $scope;
self.service = CalendarioService;
self.scope.loading = false;
self.scope.nuovoEventoCalendario = function (ev) {
$mdDialog.show({
controller: 'NuovoEventoCalendarioController',
templateUrl: '/amministratori/calendario/form',
parent: angular.element(document.body),
targetEvent: ev,
locals: {
// nada
}
}).then(function (response) {
if (response) {
//caricaListaEtichette();
// Qui apro il popup con la preview del barcode
// self.scope.anteprimaDiStampa(response, ev);
}
}, function () {
});
};
self.scope.schedulerOptions = {
date: new Date(),
views: [
"day",
//"workWeek",
"week",
{ type: "month", selected: true },
],
//editable: {
// template: $("#customEditorTemplate").html(),
dataSource: {
batch: true,
transport: {
read: {
type: "GET",
datatype: "json",
url: "https://localhost:44301/api/calendario/elenco", //This works
contentType: "application/json; charset=utf-8"
},
//read: {
// url: CalendarioService.getElencoEventiCalendario(), //This not
// dataType: "json"
//},
The strange thing is that the service's method is defined as follow
angular.module('xxx.services').factory('CalendarioService', [
'$http', function ($http) {
var baseUrl = "api/calendario";
return {
getElencoEventiCalendario: function () {
return $http.get(baseUrl + "/elenco");
},
The thing I suspect is that the method is a promise and not the URL itself... how can I fix this issue by the way?
Thanks in advance
angularjs kendo-ui
add a comment |
I've passed all day long trying to figure out while using a kendoui scheduler adapter for AngularJS the events were not loaded successfully and I found that the reason was the Service's call to get data; replacing it with the URL it correctly works, but it seems so ugly to me. Is there a way I can use it and have things working?
Here's the code I use
angular.module('xxx.controllers').controller('CalendarioController', [
'$scope', '$rootScope', '$mdDialog', '$mdToast', 'CalendarioService',
function ($scope, $rootScope, $mdDialog, $mdToast, CalendarioService) {
var self = this;
self.scope = $scope;
self.service = CalendarioService;
self.scope.loading = false;
self.scope.nuovoEventoCalendario = function (ev) {
$mdDialog.show({
controller: 'NuovoEventoCalendarioController',
templateUrl: '/amministratori/calendario/form',
parent: angular.element(document.body),
targetEvent: ev,
locals: {
// nada
}
}).then(function (response) {
if (response) {
//caricaListaEtichette();
// Qui apro il popup con la preview del barcode
// self.scope.anteprimaDiStampa(response, ev);
}
}, function () {
});
};
self.scope.schedulerOptions = {
date: new Date(),
views: [
"day",
//"workWeek",
"week",
{ type: "month", selected: true },
],
//editable: {
// template: $("#customEditorTemplate").html(),
dataSource: {
batch: true,
transport: {
read: {
type: "GET",
datatype: "json",
url: "https://localhost:44301/api/calendario/elenco", //This works
contentType: "application/json; charset=utf-8"
},
//read: {
// url: CalendarioService.getElencoEventiCalendario(), //This not
// dataType: "json"
//},
The strange thing is that the service's method is defined as follow
angular.module('xxx.services').factory('CalendarioService', [
'$http', function ($http) {
var baseUrl = "api/calendario";
return {
getElencoEventiCalendario: function () {
return $http.get(baseUrl + "/elenco");
},
The thing I suspect is that the method is a promise and not the URL itself... how can I fix this issue by the way?
Thanks in advance
angularjs kendo-ui
The $http service returns a promise. Data is extracted from a promise with the.then
method of that promise. See AngularJS $q Service API Reference - The Promise API.
– georgeawg
Nov 21 '18 at 23:29
add a comment |
I've passed all day long trying to figure out while using a kendoui scheduler adapter for AngularJS the events were not loaded successfully and I found that the reason was the Service's call to get data; replacing it with the URL it correctly works, but it seems so ugly to me. Is there a way I can use it and have things working?
Here's the code I use
angular.module('xxx.controllers').controller('CalendarioController', [
'$scope', '$rootScope', '$mdDialog', '$mdToast', 'CalendarioService',
function ($scope, $rootScope, $mdDialog, $mdToast, CalendarioService) {
var self = this;
self.scope = $scope;
self.service = CalendarioService;
self.scope.loading = false;
self.scope.nuovoEventoCalendario = function (ev) {
$mdDialog.show({
controller: 'NuovoEventoCalendarioController',
templateUrl: '/amministratori/calendario/form',
parent: angular.element(document.body),
targetEvent: ev,
locals: {
// nada
}
}).then(function (response) {
if (response) {
//caricaListaEtichette();
// Qui apro il popup con la preview del barcode
// self.scope.anteprimaDiStampa(response, ev);
}
}, function () {
});
};
self.scope.schedulerOptions = {
date: new Date(),
views: [
"day",
//"workWeek",
"week",
{ type: "month", selected: true },
],
//editable: {
// template: $("#customEditorTemplate").html(),
dataSource: {
batch: true,
transport: {
read: {
type: "GET",
datatype: "json",
url: "https://localhost:44301/api/calendario/elenco", //This works
contentType: "application/json; charset=utf-8"
},
//read: {
// url: CalendarioService.getElencoEventiCalendario(), //This not
// dataType: "json"
//},
The strange thing is that the service's method is defined as follow
angular.module('xxx.services').factory('CalendarioService', [
'$http', function ($http) {
var baseUrl = "api/calendario";
return {
getElencoEventiCalendario: function () {
return $http.get(baseUrl + "/elenco");
},
The thing I suspect is that the method is a promise and not the URL itself... how can I fix this issue by the way?
Thanks in advance
angularjs kendo-ui
I've passed all day long trying to figure out while using a kendoui scheduler adapter for AngularJS the events were not loaded successfully and I found that the reason was the Service's call to get data; replacing it with the URL it correctly works, but it seems so ugly to me. Is there a way I can use it and have things working?
Here's the code I use
angular.module('xxx.controllers').controller('CalendarioController', [
'$scope', '$rootScope', '$mdDialog', '$mdToast', 'CalendarioService',
function ($scope, $rootScope, $mdDialog, $mdToast, CalendarioService) {
var self = this;
self.scope = $scope;
self.service = CalendarioService;
self.scope.loading = false;
self.scope.nuovoEventoCalendario = function (ev) {
$mdDialog.show({
controller: 'NuovoEventoCalendarioController',
templateUrl: '/amministratori/calendario/form',
parent: angular.element(document.body),
targetEvent: ev,
locals: {
// nada
}
}).then(function (response) {
if (response) {
//caricaListaEtichette();
// Qui apro il popup con la preview del barcode
// self.scope.anteprimaDiStampa(response, ev);
}
}, function () {
});
};
self.scope.schedulerOptions = {
date: new Date(),
views: [
"day",
//"workWeek",
"week",
{ type: "month", selected: true },
],
//editable: {
// template: $("#customEditorTemplate").html(),
dataSource: {
batch: true,
transport: {
read: {
type: "GET",
datatype: "json",
url: "https://localhost:44301/api/calendario/elenco", //This works
contentType: "application/json; charset=utf-8"
},
//read: {
// url: CalendarioService.getElencoEventiCalendario(), //This not
// dataType: "json"
//},
The strange thing is that the service's method is defined as follow
angular.module('xxx.services').factory('CalendarioService', [
'$http', function ($http) {
var baseUrl = "api/calendario";
return {
getElencoEventiCalendario: function () {
return $http.get(baseUrl + "/elenco");
},
The thing I suspect is that the method is a promise and not the URL itself... how can I fix this issue by the way?
Thanks in advance
angularjs kendo-ui
angularjs kendo-ui
edited Nov 21 '18 at 23:25
georgeawg
33.5k105168
33.5k105168
asked Nov 21 '18 at 20:30
advapiadvapi
1,05311133
1,05311133
The $http service returns a promise. Data is extracted from a promise with the.then
method of that promise. See AngularJS $q Service API Reference - The Promise API.
– georgeawg
Nov 21 '18 at 23:29
add a comment |
The $http service returns a promise. Data is extracted from a promise with the.then
method of that promise. See AngularJS $q Service API Reference - The Promise API.
– georgeawg
Nov 21 '18 at 23:29
The $http service returns a promise. Data is extracted from a promise with the
.then
method of that promise. See AngularJS $q Service API Reference - The Promise API.– georgeawg
Nov 21 '18 at 23:29
The $http service returns a promise. Data is extracted from a promise with the
.then
method of that promise. See AngularJS $q Service API Reference - The Promise API.– georgeawg
Nov 21 '18 at 23:29
add a comment |
1 Answer
1
active
oldest
votes
Like already said you need to use .then as the $http service returns a promise. You can try something like that:
dataSource: {
transport: {
read: function (e) {
CalendarioService.getElencoEventiCalendario()
.then(function success(response) {
e.success(response.data)
}, function error(response) {
alert('something went wrong')
console.log(response);
})
}
}
}
Hope this helps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420036%2fuse-an-angularjs-service-in-place-of-the-url-in-kendoui-scheduler%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Like already said you need to use .then as the $http service returns a promise. You can try something like that:
dataSource: {
transport: {
read: function (e) {
CalendarioService.getElencoEventiCalendario()
.then(function success(response) {
e.success(response.data)
}, function error(response) {
alert('something went wrong')
console.log(response);
})
}
}
}
Hope this helps.
add a comment |
Like already said you need to use .then as the $http service returns a promise. You can try something like that:
dataSource: {
transport: {
read: function (e) {
CalendarioService.getElencoEventiCalendario()
.then(function success(response) {
e.success(response.data)
}, function error(response) {
alert('something went wrong')
console.log(response);
})
}
}
}
Hope this helps.
add a comment |
Like already said you need to use .then as the $http service returns a promise. You can try something like that:
dataSource: {
transport: {
read: function (e) {
CalendarioService.getElencoEventiCalendario()
.then(function success(response) {
e.success(response.data)
}, function error(response) {
alert('something went wrong')
console.log(response);
})
}
}
}
Hope this helps.
Like already said you need to use .then as the $http service returns a promise. You can try something like that:
dataSource: {
transport: {
read: function (e) {
CalendarioService.getElencoEventiCalendario()
.then(function success(response) {
e.success(response.data)
}, function error(response) {
alert('something went wrong')
console.log(response);
})
}
}
}
Hope this helps.
answered Nov 22 '18 at 8:12
SehaxXSehaxX
5681616
5681616
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420036%2fuse-an-angularjs-service-in-place-of-the-url-in-kendoui-scheduler%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The $http service returns a promise. Data is extracted from a promise with the
.then
method of that promise. See AngularJS $q Service API Reference - The Promise API.– georgeawg
Nov 21 '18 at 23:29