0
votes

I have a Hottowel application and a Durandal modal dialog for creating a new entity. In it's viewmodel I have create and cancel functions, which both call close on success. The problem is that modal doesn't close when I call close from another function. It does close when I call it directly.

The code:

var close = function () {
    dialog.close(this);
};

var cancel = function () {
    datacontext.cancelChanges();
    close();
};

var create = function () {
    return datacontext.saveChanges()
        .then(close);
};
1
Can you paste the code of whole model? It's hard to tell what can be wrong looking only at these functions as they seems pretty fine. - karol.barkowski
You are forgetting that the context of this changes depending on how the close function is called. You need to make sure that this is your viewmodel; otherwise you will never get it to close. - Brett
You are right, but the results are still strange... Debugging showed that when I all close on it's own, this is a Window object whose getDialog() method returns the dialog. Calling close from another function makes this a Window object whose getDialogmethod returns undefined... Beats me... Anyway, calling vm.close() resolves the issue. - Sljux

1 Answers

1
votes

What do you mean it doesn't work when you call it from another function? Are you sure that your context is still the same when you are calling it?

var close = function () {
    var self = this;
    dialog.close(self);
};

Try to update your close function to this and if it still isn't closing then could you please explain where you are calling it that it isn't closing from? From inside the same view model, from another view model, which function, etc...