Angularjs Full Calendar不显示事件

Angularjs Full Calendar doesn't display events

本文关键字:显示 事件 Calendar Full Angularjs      更新时间:2023-09-26

我正在使用该 https://github.com/angular-ui/ui-calendar 来使用Angularjs中的FullCalendar。

它显示日历并且不显示任何错误;

<div class="calendar" ng-model="eventSources" id="eventCalendar" calendar="calendar" config="uiConfig.calendar" ui-calendar="uiConfig.calendar"></div>
但它

不会显示事件,我不确定我是否做对了,但它没有显示错误,我搜索了互联网,还没有找到解决方案。谁能给我一个提示,为什么它不起作用?

以下是代码片段:

var calApp = angular.module('usercalapp', ['ui.bootstrap','dialogs','ngCookies','ui.calendar']);
calApp.controller('UserCtrl', function ($scope, $http, $rootScope, $timeout,,$dialogs,$cookieStore,$compile,uiCalendarConfig) 
{
    $scope.eventSources = [];
    $scope.calendar = $('#calendar');
    $scope.uiConfig = {
       calendar : {
          height: 450,
           editable: true,
           header: {
            left: 'month basicWeek basicDay',
            center: 'title',
            right: 'today prev, next'
            },
        dayClick: $scope.alertEventOnClick,
        eventDrop: $scope.alertOnDrop,
        eventResize: $scope.alertOnSize
    }
};
$scope.cal_func = function()
{
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    $scope.eventSources = [
    {
        title: 'All Day Test Event',
        start: new Date(y, m, 1)
    },
    {
        title: 'Long Test Event',
        start: new Date(y, m, d - 5),
        end: new Date(y, m, d - 2)
    },
    {
        title: 'Test Birthday Party',
        start: new Date(y, m, d + 1, 19, 0),
        end: new Date(y, m, d + 1, 22, 30),
        allDay: false
    }];
    $scope.calendar.fullCalendar('refetchEvents');
};
$scope.showColorPicker = function(index)
{
    $cookieStore.showuserid = index;
    dlg = $dialogs.create('/dialogs/pickColor.html','pickColorCtrl',{},{key:false ,back:'static'});
    dlg.result.then(function()      
    {       
        $scope.cal_func();
    });
};
....

所以我希望用户选择一种颜色,然后日历中应该显示 3 个事件,但没有任何反应......

在这里,在您的eventSources中,您直接输入了事件。

您应该做的是提供存储事件的数组列表。像这样: $scope.eventSources = [$scope.myEvents, $scope.someOtherArray, $scope.otherEvents];

$scope.myEvents,你可以把你的事件。

$scope.myEvents = [
  {
    title: 'All Day Test Event',
    start: new Date(y, m, 1)
  },
  {
    title: 'Long Test Event',
    start: new Date(y, m, d - 5),
    end: new Date(y, m, d - 2)
  },
  {
    title: 'Test Birthday Party',
    start: new Date(y, m, d + 1, 19, 0),
    end: new Date(y, m, d + 1, 22, 30),
    allDay: false
  }
];

$scope.someOtherArray, $scope.otherEvents可以是事件的其他来源。

就颜色而言,您可以通过事件对象或事件源对象自定义它们

$scope.someOtherArray = [];
$scope.weeklyEvents = {
    color: '#656565',
    textColor: 'white',
    events: []
};
$scope.otherEvents = {
    color: '#B2B2B2',
    textColor: 'black',
    events: []
};

您可以修改代码以使用上述两种方法之一(访问这些链接)。

让我工作的东西是。

取而代之的是这个。

$scope.eventSources = [$scope.myEvents, $scope.someOtherArray, $scope.otherEvents];

试试这个

$scope.eventSources.push($scope.myEvents);

我用过

$scope.callCalendar = function (){
... ...
};

在 html 文件中:

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

事件没有显示在日历中;但我发现$scope.eventsconsole.log($scope.events)中具有正确的值。