【发布时间】:2019-04-24 11:49:51
【问题描述】:
我一整天都在试图弄清楚在使用 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"
//},
奇怪的是服务的方法定义如下
angular.module('xxx.services').factory('CalendarioService', [
'$http', function ($http) {
var baseUrl = "api/calendario";
return {
getElencoEventiCalendario: function () {
return $http.get(baseUrl + "/elenco");
},
我怀疑该方法是一个承诺,而不是 URL 本身......我该如何解决这个问题?
提前致谢
【问题讨论】:
-
$http 服务返回一个承诺。使用该承诺的
.then方法从该承诺中提取数据。见AngularJS $q Service API Reference - The Promise API。