Angular again hide notification message after x seconds or change page

I am new to angular, now I was able to show a warning message when someone asks for a new password from our application:

Usermodel:

.service('userModel', ['$q', '$http', 'authorizedTracker', function($q, $http, authorizedTracker) {
    this.passwordreset = function(token) {

    var deferred = $q.defer();

    $http({
        method: 'GET',
        url: '/reset/'+token
    })

    .then(function(response) {

    if (!_(response.data).has('user')) {
        deferred.reject('unkown user id');
    }

    model.resetted = true;


    }, function(error) {
        deferred.reject(error.data.message);
    });

    authorizedTracker.addPromise( deferred.promise)

    return deferred.promise;
};

So, if true is selected, a message will appear, see below:

HTML:

<!-- Succes-->
<div class="alert alert-success animated fadeInDown" ng-cloak  ng-show="userModel.resetted">
    <strong><i class="icon-attention"></i>Success!</strong> New password is sent to your e-mail
</div>

But now I want to hide the warning after x seconds or if the user clicks on another page. How is this possible? Any solution?

+4
source share
2 answers

you should use the $ timeout service (similar to window.setTimeout in your own javascript).

In your code you should add the following code

...
model.resetted = true;

$timeout(function() {

    model.resetted = false;

}, xxx)//replace xx by the amount of milisecond you want

, , http://plnkr.co/edit/Qt39x5Xo5JhP61QHYLwO?p=preview

+5

X $timeout.

model.resetted = true;

$timeout(function() {
  model.resetted = false;
}, X); // X in milliseconds
+2

All Articles