AngularJs - get return value of a function
I am using a FullCalendar plugin in an Angular project and am trying to alert the value about the plugin selection method.
//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>
As you can see above in the directive, when I select a day, I pass a function onSelect()
that has a warning from the controller. I am trying to alert the first 2 return values (start and end), but I am getting undefined values.
What's wrong with my code? I would appreciate it if you could update the plunker.
+3
source to share
1 answer
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>
updated plunker
+3
source to share