Use an AngularJS Service in place of the url in KendoUI Scheduler












0















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










share|improve this question

























  • 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
















0















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










share|improve this question

























  • 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














0












0








0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 8:12









        SehaxXSehaxX

        5681616




        5681616
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules