0

I trying to show an message to the user that will disappear after 6 seconds using angular $timeout. Unfortunately I've been unable to make it work in conjunction with angular-translate (that I use for translations).

So this code works (without $translate service):

this.showMessage = function(type, text) {
    message.isVisible = true;
    message.type = type;
    message.text = text;
    $timeout(this.hideMessage, 6 * 1000);
}

But when I make the call inside $translate service response it doesn't (I already checked that the promise is correctly resolved):

this.showMessage = (type, translationId) {
    $translate(translationId).then(function (text) {
        //This works just fine.
        message.isVisible = true;
        message.type = type;
        message.text = text;
        //But hideMessage never gets called.
        $timeout(this.hideMessage, 6 * 1000);
    });
}

Can someone help? Thank you.

belyid
  • 841
  • 2
  • 12
  • 28

0 Answers0