在Angular JS中渲染之后的angular-ui / ui-calendar更改事件源

时间:2014-12-27 16:05:03

标签: angularjs fullcalendar angular-ui

我正在尝试在我的Angular Js应用程序中使用angular-ui / ui-calendar(FullCalendar)。 我有选择框列出了一些项目,根据选择的项目,我的事件源网址需要更新。所以在控制器中,我确实更新了它,但是日历仍然没有使用更新的URL,而且一旦源被更改,我还需要日历来刷新/渲染。 根据此link需要删除和添加事件源。 我是Jquery和Angular的新手,所以如果有人能解释我怎样才能在角度js中做到这一点,我将不胜感激。

我的控制器的一些位置,我设置了url源,但我认为这不是正确的方法,而且它也无法正常工作。

$scope.locationId = 0
$scope.url = "./api/ev/event/calendarByLocationId?locationId=" + $scope.locationId;
$scope.eventSource = {
        url : $scope.url
    };

$scope.setURL = function(locationId) {
    $scope.locationId = locationId
    $scope.url = "./api/ev/event/calendarByLocationId?locationId=" + $scope.locationId;
    $scope.eventSource = {
        url : $scope.url
    };
    $scope.eventSources = [ $scope.eventSource ];
}

2 个答案:

答案 0 :(得分:2)

不使用refetchEvents,下面的代码适用于我。添加新事件源后,Calendar会自动从新源获取新数据。

// This function is called to change the event source. When
// ever user selects some source in the UI
$scope.setEventSource = function(locationId) {
// remove the event source.
uiCalendarConfig.calendars['myCalendar'].fullCalendar('removeEventSource', $scope.eventSource);
// Create the new event source url
$scope.eventSource = {url : "./api/ev/event/calendarByLocationId?locationId=" + locationId};
// add the new event source.
uiCalendarConfig.calendars['myCalendar'].fullCalendar('addEventSource', $scope.eventSource);
}

答案 1 :(得分:1)

我正在考虑添加和删除事件源。似乎有问题。

但暂时,我所拥有的是一个REST网址。更新后,数据会更新。到那时我通过触发这个程序使程序刷新同一个url上的事件。这样可以再次刷新和从数据库中获取URL。

$scope.myCalendar.fullCalendar( 'refetchEvents' );

您的HTML代码应如下所示:

<div class="calendar" ng-model="eventSources" calendar="myCalendar" config="uiConfig.calendar" ui-calendar="uiConfig.calendar"></div>

希望这有帮助。