x秒或页面更改后再次出现角度隐藏警报消息

Eri*_*Ven 5 javascript angularjs

我对角度很新,现在当有人从我们的应用程序请求新密码时,我能够显示警告消息:

的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;
};
Run Code Online (Sandbox Code Playgroud)

因此,如果重置为true,则会显示该消息,请参阅以下内容:

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>
Run Code Online (Sandbox Code Playgroud)

但现在我想在x秒后隐藏警报,或者如果用户点击另一页.怎么可能?有解决方案吗

Pol*_*hon 6

你应该使用$ timeout服务(symilar到本机javascript中的window.setTimeout).

在您的代码中,您应该添加以下代码

...
model.resetted = true;

$timeout(function() {

    model.resetted = false;

}, xxx)//replace xx by the amount of milisecond you want
Run Code Online (Sandbox Code Playgroud)

这是一个例子,希望它能帮到你 http://plnkr.co/edit/Qt39x5Xo5JhP61QHYLwO?p=preview

  • 固定,对不起^^.在stackoverflow文本框中编码很困难 (2认同)