Flash消息不会消失(sachinchoolur Flash模块)AngularJs [英] Flash Messages don't disappear (sachinchoolur flash module) AngularJs

查看:62
本文介绍了Flash消息不会消失(sachinchoolur Flash模块)AngularJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sachinchoolur的angularjs-flash 在AngularJs应用程序中生成Flash消息模块.

I am trying to make flash messages in my AngularJs app with the use of sachinchoolur's angularjs-flash module.

闪光灯可以工作,但在设置超时后它们不会消失.

The flashes work but they don't disappear after the set TimeOut.

我正确地遵循了文档,并在plnkr中编写了最少的代码来演示问题.

I followed the documentation correctly and I made a minimum code in plnkr to demonstrate the problem.

https://plnkr.co/edit/OaLbAjqZDmeWoPxr5uaf?p=preview

app.js

// public/js/app.js
angular.module('myApp', ['ngFlash'


])
.config(['$locationProvider', '$httpProvider', 'FlashProvider',
  function($locationProvider, $httpProvider, FlashProvider) {
    FlashProvider.setTimeout(5000);

}])


.controller('MainCtrl', function($scope, $rootScope, $http, $location, $window, Flash) {

  $scope.test = "test";
  $scope.show = function() {
      var message = 'Welcome '
      var id = Flash.create('success', message, 0, {class: 'custom-class', id: 'custom-id'}, true);
      alert("show");
  }
});

html模板:

<!DOCTYPE html>
<html ng-app="myApp">

  <head>
    <link data-require="bootstrap@*" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.0/angular-ui-router.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/script.js/2.4.0/script.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>


    <script type="text/javascript" src="app.js"></script>
    <script type="text/javascript" src="angular-flash.js"></script>
  </head>

  <body ng-controller="MainCtrl">

    <h1>Hello Plunker!</h1>
    {{ test }}

    <flash-message duration="5000"></flash-message>
    <button ng-click="show()">Test</button>


  </body>

</html>

推荐答案

根据使用方法| angular-flash ,用于 Flash.create(...)

According to how to use | angular-flash for Flash.create(...),

第三个参数(数字,可选)是显示闪光灯的持续时间. 0 不会自动隐藏Flash (用户需要点击右上角的叉号).

Third argument (number, optional) is the duration of showing the flash. 0 to not automatically hide flash (user needs to click the cross on top-right corner).

因此,我将您的 Flash.create 函数更改为包含 5000 而不是您超时的 0 :

Hence, I changed your Flash.create function to contain 5000 instead of 0 which was your timeout:

Flash.create('success', message, 5000, {
  class: 'custom-class',
  id: 'custom-id'
}, true);

而且,它有效!

这是 工作示例

这篇关于Flash消息不会消失(sachinchoolur Flash模块)AngularJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆