如何使用“控制器为”语法获取AngularJS ui-calendar的日历对象?

前端之家收集整理的这篇文章主要介绍了如何使用“控制器为”语法获取AngularJS ui-calendar的日历对象?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从angular-ui使用 ui-calendar.它非常好用且易于使用.

但是,我无法获取日历对象来调用fullCalendar()并在日历上执行某些功能.

该文档仅提供了使用$scope方法的示例,但我使用控制器作为John Papa和其他人推荐的vm方法.我试过用这种方式:

<div data-ng-controller="races as vm">
    <div ui-calendar="vm.calendarConfig" calendar="vm.calendar"></div>
</div>

在比赛控制器中我有以下内容

vm = this;
vm.calendarConfig = { header: {...} };
vm.calendar = {};

// somewhere else in a separate click event
vm.calendar.fullCalendar('prev');    // ---> exception

最后一行抛出异常Object没有方法’fullCalendar’.

只是想知道我缺少什么,如果有人有一个使用ui-calendar与控制器作为vm语法的例子.

这是羽毛球:http://plnkr.co/edit/DPo9meJHx19bREYFLhDh

感谢 Josh Kurz的帮助.以下是我最终要做的事情:我使用了$scope和controller的混合方法.
基本上,我在我的控制器上添加了对$scope的依赖.当我需要访问实际的日历控件时,我使用$scope.calendar.fullCalendar(‘…’). plunker已更新,但这是脚本文件中的核心:
angular.module('app').controller(controllerId,['$scope',races];
function races($scope) {
    var vm = this;
    ...
    function next() {
        $scope.calendar.fullCalendar('next');
    }
}

并在HTML中:

...
<div ui-calendar ng-model="vm.eventSources" calendar="calendar"></div>
...

不像我想的那样干净,但它似乎仍然足够干净,符合我的目的.

猜你在找的Angularjs相关文章