我在Angular项目中使用FullCalendar插件并尝试提醒插件的select方法的值。
//Directive
app.directive('calendar', function(){
return {
restrict: 'A',
scope: {
select: '&'
},
link: function(scope, element, attrs) {
element.fullCalendar({
selectable: true,
select: function(start, end, allDay) {
scope.select(start, end);
//alert(start);
}
});
}
}
})
app.controller('calendarCtrl', function() {
this.onSelect = function(arg, arg2) {
alert(arg + '' + arg2)
}
});
HTML
<body ng-controller="calendarCtrl as clctrl">
<div calendar select="clctrl.onSelect()"></div>
</body>
正如您在指令中看到的,在选择一天时,我传递了来自控制器的警告的onSelect()
函数。我试图提醒前2个返回值(开始和结束),但我得到了未定义的值。
我的代码有什么问题?如果你能更新plunker,我将不胜感激。
答案 0 :(得分:3)
var app = angular.module('app', []);
//Controller
app.controller('calendarCtrl', function() {
this.onSelect = function(arg, arg2) {
alert(arg + ' ' + arg2)
}
});
//Directive
app.directive('calendar', function(){
return {
restrict: 'A',
scope: {
select: '&'
},
link: function(scope, element, attrs) {
//Generate the Calendar
element.fullCalendar({
selectable: true,
//On Day Select
select: function(start, end, allDay) {
scope.select({start: start, end: end});
//alert(start);
}
});
}
}
})
<div calendar select="clctrl.onSelect(start, end)"></div>
更新plunker