私はcustom cell templateとcell modifierの角型ブートストラップカレンダーを使用しています。私のコントローラでは、修飾子関数が呼び出される前にcellModifier関数で使用されるサービスからいくつかの設定データを取得する必要があります。角度サービスへの非同期呼び出しが完了した後にコントローラをコールします。
(function() {
angular.module('formioAppBasic')
.controller('calendarController', function($scope, moment, calendarConfig, $http, Formio, shiftService, AppConfig) {
var vm = this;
calendarConfig.templates.calendarMonthCell = 'views/calendar/dayTemplate.html';
calendarConfig.dateFormatter = 'moment';
vm.events = [];
vm.calendarView = 'month';
vm.viewDate = moment().startOf('month').toDate();
vm.appConfig = AppConfig;
vm.currentUser = Formio.getUser();
// Get station config.
shiftService.getStationConfig().then(function(data) {
vm.configSlots = data;
});
shiftService.getShiftsMonth(token, startDate, endDate)
.then(onShifts, onError);
var onShifts = function(data) {
vm.events = data;
};
var onError = function(error) {
vm.error = 'There was an error.';
};
var startDate = moment(this.viewDate).toISOString();
var endDate = moment(this.viewDate).endOf('month').toISOString();
var endpoint = APP_URL + '/shift/submission';
var token = Formio.getToken();
vm.cellModifier = function(cell) {
// Do work to create the data in the custom cell.
};
$scope.$on('$destroy', function() {
calendarConfig.templates.calendarMonthCell = 'mwl/calendarMonthCell.html';
});
});
})();
使用する必要がある設定データは、shiftServiceサービスへの2回の呼び出しから返され、その部分はうまくいきます。 docsに示すように、セル修飾子関数はmwl-calendar
指示文から呼び出されます。
<h1>Shift Calendar</h1>
<h2 class="text-center">{{ calendarTitle }}</h2>
<ng-include src="'views/calendar/calendarControls.html'"></ng-include>
<mwl-calendar
view="vm.calendarView"
view-date="vm.viewDate"
events="vm.events"
view-title="calendarTitle"
cell-is-open="true"
cell-modifier="vm.cellModifier(calendarCell)"
>
</mwl-calendar>
それがあるように私は私のコードを実行するとshiftService.getStationConfig
とshiftService.getShiftsMonth
への呼び出しが返される前に、cellModifierが呼び出されます。
コントローラ外からcellModifierが呼び出されたことを考慮して、shiftModeの他の2つの呼び出しによってデータが返されるまでcellModifierが呼び出されないようにコードを構造化する方法はありますか?
ありがとうございました。