我已经花了整整一天的时间,试图弄清楚在为AngularJS使用kendoui调度程序适配器时,事件未成功加载,我发现原因是服务方要求获取数据;用URL替换它可以正常工作,但是对我来说似乎很难看。我有办法使用它并使事情正常吗?
这是我使用的代码
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"
//},
奇怪的是,该服务的方法定义为follow
angular.module('xxx.services').factory('CalendarioService', [
'$http', function ($http) {
var baseUrl = "api/calendario";
return {
getElencoEventiCalendario: function () {
return $http.get(baseUrl + "/elenco");
},
我怀疑的是,该方法是一个承诺而不是URL本身...如何解决这个问题?
预先感谢
答案 0 :(得分:0)
就像已经说过的那样,您需要使用.then,因为$ http服务返回了promise。您可以尝试这样的事情:
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);
})
}
}
}
希望这会有所帮助。