本文介绍了将 FullCalendar 方法与 AngularUI 包装器一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 AngularUI 的日历包装器集成到我的应用程序中,并且日历初始化工作正常.但是,我不知道如何从这里调用日历方法.这是我的控制器代码:

I'm trying to integrate AngularUI's calendar wrapper into my application, and the calendar initialization works fine. However, I don't see how I can call calendar methods from here. Here's my controller code:

$scope.events = [];
$scope.calendarOptions = {
    calendar: {
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        defaultView: 'agendaWeek',
        selectable: true,
        selectHelper: true,
        select: function(start, end, allDay) {
            var title = prompt('Event Title:');
            if (title) {
                $scope.$apply(function(){
                    $scope.events.push({
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay
                    });
                });

            }
            // should call 'unselect' method here
        },
        editable: true
    }
};
$scope.eventSources = [$scope.events];

如何从日历调用方法?它不在我的控制器范围内,我已经检查了范围对象内的所有地方.

How do I call methods from the calendar? It's not in my controller's scope, I've checked everywhere inside the scope object.

我在 uiCalendar 指令代码中找到了这个:

I found this inside the uiCalendar directive code:

 scope: {ngModel:'=',config:'='},

据我所知,这意味着日历是在一个孤立的范围内创建的.所以不能在日历上调用任何方法.但是,在演示中我发现了这一行:

By my understanding, this means that the calendar is created in an isolated scope. So no methods can be called on the calendar. HOWEVER, in the demo I found this line:

 /* Change View */
$scope.changeView = function(view) {
    $scope.myCalendar.fullCalendar('changeView',view);
};

所以演示可以调用日历上的方法而我不能?我也无法复制这个.

So the demo can call methods on the calendar and I can't? I can't replicate this either.

如有任何帮助理解或解决问题,我们将不胜感激.

Any help understanding or fixing the issue would be appreciated.

推荐答案

好的,在源代码中很明显,但第一眼我没明白.这是一个相关的片段:

Okay, so it was pretty obvious in the source code, but I didn't understand on first glance. Here's a relevant snippet:

if(attrs.calendar){
    scope.calendar = scope.$parent[attrs.calendar] = elm.html('');
}else{
    scope.calendar = elm.html('');
}

这会将日历绑定到您在 HTML 中编写日历指令时声明的名称下的父作用域.例如

This binds the calendar to the parent scope under the name that you declare when you write the calendar directive in your HTML. e.g.

<div ui-calendar="options" calendar="my-calendar-name" ng-model="events"></div>

这意味着我可以在我的控制器范围内调用日历的方法.这是一个我什至没有考虑过的功能实现!我们需要此脚本的一些文档.

This means I can call on the calendar's methods in my controller's scope. It was a feature implementation that I hadn't even considered yet! We need some docs for this script.

这篇关于将 FullCalendar 方法与 AngularUI 包装器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:04