search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to call custom function in onTimeRangeSelected

Asked by Hiren
5 years ago.

In angular 6 i have many custom function so can call that function after add new task with this method onTimeRangeSelected. Example Like Below :

onTimeRangeSelected: function (args) {
var dp = this;
DayPilot.Modal.prompt("Create a new task:", "").then(function(modal) {
dp.clearSelection();
if (!modal.result) { return; }
dp.events.add(new DayPilot.Event({
start: args.start,
end: args.end,
id: DayPilot.guid(),
resource: args.resource,
text: modal.result
}));
});
this.Callfunctin();
},

Answer posted by Dan Letecky [DayPilot]
5 years ago.

When you use the JavaScript declaration style you won't be able to access the component object as "this":

onTimeRangeSelected: function(args) {
  // ...
  this.myFunction();  // won't work
}

It's necessary to use an arrow function - ES6/TypeScript syntax (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions):

onTimeRangeSelected: args => {
  // ...
  this.myFunction();  // works as expected
}
Comment posted by Hiren
5 years ago.

i have resolve this using below example :

DayPilot.Modal.prompt("Create a new task:", "",this).then(function(modal) {
if (!modal.result) { return; }
this.myfunction();
}

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.