Flash 消息不会消失(sachinchoolur flash 模块)AngularJs

Flash Messages don't disappear (sachinchoolur flash module) AngularJs

我正在尝试使用 sachinchoolur's angularjs-flash 模块在我的 AngularJs 应用程序中制作即时消息。

闪光灯工作,但在设置的超时后不会消失。

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

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>

根据how to use | angular-flash Flash.create(...),

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,这是您的超时:

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

而且,它有效!

这里是working example