previous questionで詳述するように、私はAngular Bootstrap Calendarを使用しており、ドキュメントごとに、それぞれの内部のデータをカスタマイズできるように指示とconfig細胞。ここにコントローラがあります:アングル・ブートストラップ・カレンダー付きセル・データ関数に追加データを渡す
(function() {
angular.module('myApp')
.controller('calendarController', function($scope, $state, moment, calendarConfig, $http, Formio, shiftService) {
var vm = this;
calendarConfig.templates.calendarMonthCell = 'views/calendar/dayTemplate.html';
calendarConfig.dateFormatter = 'moment';
vm.events = [];
vm.calendarView = 'month';
vm.viewDate = moment().startOf('month').toDate();
var startDate = moment(this.viewDate).toISOString();
var endDate = moment(this.viewDate).endOf('month').toISOString();
var endpoint = 'https://abcdefghijklmno.form.io/shift/submission';
var token = Formio.getToken();
var shifts = shiftService.getShiftsMonth(token, startDate, endDate);
vm.cellModifier = function(cell, shifts) {
cell.text = 'Test Text';
//console.log(cell);
};
$scope.$on('$destroy', function() {
calendarConfig.templates.calendarMonthCell = 'mwl/calendarMonthCell.html';
});
});
})();
と私のサービスはデータを取得します。
(function() {
angular
.module('myApp')
.service('shiftService', shiftService);
shiftService.$inject = ['$http'];
function shiftService($http) {
var getShiftsMonth = function (token, startDate, endDate) {
var config = {
headers: {
'x-jwt-token' : token
},
params: {
'date.date__gte': startDate,
'date.date__lte': endDate
// limit: 10
}
};
return $http.get('https://abcdefghijklno.form.io/shift/submission', config)
.then(function(response) {
return response.data;
});
};
var addNameToShift = function(locationid) {
return $http.get('/my/url/' + locationid);
};
return {
getShiftsMonth: getShiftsMonth,
addNameToShift: addNameToShift
};
}
})();
は、私は私が何をしたいのか(私はしたくない1回の呼び出しで全体の月のすべてのデータを取得し、セル変更関数に渡している、APIエンドポイントからカスタムデータを取得します1か月間にAPIエンドポイント〜30回の別々の時間にヒットする必要があります)。しかし、cellModifierはcalendarHelperサービスから呼び出されるため、返されたデータをcellModifier関数に渡す方法はありません。コントローラ の$ rootScopeに追加するだけでよいので、修飾子で利用できるようにするか、そこにそのデータを取得するより良い方法がありますか?
ありがとうございました。