Subbarami Reddy Subbarami Reddy - 2 months ago 38
HTML Question

how to give dtStart and until for Recurring event using angular bootstrap calendar?

In angular js service file I am using RRULE.WEEKLY here I want to give dtStart and until dynamically with multiple events

$scope.$watchGroup([
$scope.calendarView,
angular.forEach(data, function (value, index) {
if(value.recursOn === 'week'){
$scope.viewDate = value.startDate,
$scope.viewEndDate = value.endDate
}
}),
], function() {

// Use the rrule library to generate recurring events: https://github.com/jkbrzt/rrule
var rule = new RRule({
freq: RRule.WEEKLY,
interval: 1,
byweekday: [RRule.MO],
dtstart: moment($scope.viewDate).toDate(),
until: moment($scope.viewEndDate).toDate()
});

angular.forEach(data, function (value, index) {
if(value.recursOn !== 'week'){
$scope.schedules.push(value);
}

});

rule.all().forEach(function(date) {
angular.forEach(data, function (value, index) {
if(value.recursOn === 'week'){
$scope.schedules.push({
matchDesc: value.matchDesc,
teamName: value.teamName,
color: calendarConfig.colorTypes.success,
startDate: new Date(date)
});
}

});
});

});


In this I am trying to get multiple events with Recurring weekly, So for this I am using angular for each to get events from database but how to set multiple events start date and end date to dtStart and until.

Answer

For this you have do like this.

var rule = {};
       $scope.$watchGroup([
                $scope.calendarView,

            ], function() {
       angular.forEach(data, function (value, index) {
       // Use the rrule library to generate recurring events:https://github.com/jkbrzt/rrule

       if(value.recursOn === 'week'){
              rule = new RRule({
               freq: RRule.WEEKLY,
               interval: 1,
               byweekday: [RRule.MO],
               dtstart: moment(value.startDate).toDate(),
               until: moment(value.endDate).toDate()
             });
          }

       rule.all().forEach(function(date) {

                if(value.recursOn === 'week'){
              $scope.schedules.push({
                    matchDesc: value.matchDesc,
                    teamName: value.teamName,
                    color: calendarConfig.colorTypes.success,
                    startDate: new Date(date)
               });
              }
          });   
         });


    });

It's working for Recurring event weekly using RRULE.WEEKLY with dtstart and until dynamically to no of events.

Hope it would help.