github地址: https://github.com/jirikavi/AngularJS-Toaster

参考博客: https://www.cnblogs.com/youzhuxiaoyao/p/4953642.html

AngularJS Toaster是一个 AngularJS 提示框.基于angular v1.2.6 及以上和angular-animate. (推荐使用 /1.2.8/angular-animate.js, 因为高版本会有怪异闪烁.)
引入脚本
<link href="https://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/0.4.16/toaster.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js" ></script>
<script src="https://code.angularjs.org/1.2.0/angular-animate.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/0.4.16/toaster.min.js"></script>
用法1:
添加指令
<toaster-container></toaster-container>
编写弹窗调用函数
angular.module('main', ['toaster', 'ngAnimate'])
    .controller('myController', function($scope, toaster) {
        $scope.pop = function(){
            toaster.pop('success', "title", "text");
        };
    });
  调用
  <div ng-controller="myController">
    <button ng-click="pop()">Show a Toaster</button>
</div>
添加关闭按钮
方式一: 全局的,为所有弹窗添加 <toaster-container toaster-options="{'close-button': true}"></toaster-container>

方式二:给close-btn 属性传递一个对象 <toaster-container toaster-options="{'close-button':{ 'toast-warning': true, 'toast-error': false } }"></toaster-container>
表示warning类型的弹窗显示关闭按钮,error类型的则不显示,不设置默认为false不显示

方式三 :在控制器里面设置: toaster.pop({
                type: 'error',
                title: 'Title text',
                body: 'Body text',
                showCloseButton: true
            });
 这种设置会覆盖页面的属性设置,不会污染其他的弹窗设置

 自定义关闭按钮的html
<toaster-container toaster-options="{'close-html':'<button>Close</button>', 'showCloseButton':true}"></toaster-container>
    或者
toaster.pop({
        type: 'error',
        title: 'Title text',
        body: 'Body text',
        showCloseButton: true,
        closeHtml: '<button>Close</button>'
});

bodyOutputType(body的渲染类型)  可以接受 trustedHtml', 'template', 'templateWithData', 'directive'四种类型
trustedHtml:使用此类型 toaster会调用$sce.trustAsHtml(toast.body)如果解析成功将会通过ng-bind-html指令被绑定到toaster,失败会抛出一个异常
作为模板处理
例如:    $scope.pop = function(){
        toaster.pop({
            type: 'error',
            title: 'Title text',
            body: 'cont.html',
            showCloseButton: true,
            bodyOutputType:'template',
            closeHtml: '<span>wqeqwe</span>'
        });
    };
作为指令来处理
toaster.pop({
    type: 'info',
    body: 'bind-unsafe-html',
    bodyOutputType: 'directive'
});

.directive('bindUnsafeHtml', [function () {
    return {
        template: "<span style='color:orange'>Orange directive text!</span>"
    };
}])

带数据的指令
toaster.pop({
        type: 'info',
        body: 'bind-name',
        bodyOutputType: 'directive',
        directiveData: { name: 'Bob' }
});

.directive('bindName', [function () {
      return {
          template: "<span style='color:orange'>Hi {{directiveData.name}}!</span>"
      };
}])

<toaster-container toaster-options="{'body-output-type': 'template'}"></toaster-container>

回调函数,当弹窗被移除的时候调用,可以用于链式调用弹窗
toaster.pop({
            title: 'A toast',
            body: 'with a callback',
            onHideCallback: function () { 
                toaster.pop({
                    title: 'A toast',
                    body: 'invoked as a callback'
                });
            }
});

设置弹窗位置
位置信息可以去css文件里面看需要什么位置,直接把属性值改成相应class就行,如果没有符合的就自己手动添加一个到toaster.css文件然后把名字赋值给属性就行
<toaster-container toaster-options="{'position-class': 'toast-top-full-width'}"></toaster-container>

<toaster-container toaster-options="{'position-class': 'toast-top-center', 'close-button':true}"></toaster-container>

AngularJS Toaster的简单介绍的更多相关文章

  1. [原创]关于mybatis中一级缓存和二级缓存的简单介绍

    关于mybatis中一级缓存和二级缓存的简单介绍 mybatis的一级缓存: MyBatis会在表示会话的SqlSession对象中建立一个简单的缓存,将每次查询到的结果结果缓存起来,当下次查询的时候 ...

  2. 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍

    一.pandas 是什么 pandas 是基于 NumPy 的一个 Python 数据分析包,主要目的是为了数据分析.它提供了大量高级的数据结构和对数据处理的方法. pandas 有两个主要的数据结构 ...

  3. 利用Python进行数据分析(4) NumPy基础: ndarray简单介绍

    一.NumPy 是什么 NumPy 是 Python 科学计算的基础包,它专为进行严格的数字处理而产生.在之前的随笔里已有更加详细的介绍,这里不再赘述. 利用 Python 进行数据分析(一)简单介绍 ...

  4. yii2的权限管理系统RBAC简单介绍

    这里有几个概念 权限: 指用户是否可以执行哪些操作,如:编辑.发布.查看回帖 角色 比如:VIP用户组, 高级会员组,中级会员组,初级会员组 VIP用户组:发帖.回帖.删帖.浏览权限 高级会员组:发帖 ...

  5. angular1.x的简单介绍(二)

    首先还是要强调一下DI,DI(Denpendency Injection)伸手获得,主要解决模块间的耦合关系.那么模块是又什么组成的呢?在我看来,模块的最小单位是类,多个类的组合就是模块.关于在根模块 ...

  6. Linux的简单介绍和常用命令的介绍

    Linux的简单介绍和常用命令的介绍 本说明以Ubuntu系统为例 Ubuntu系统的安装自行百度,或者参考http://www.cnblogs.com/CoderJYF/p/6091068.html ...

  7. iOS-iOS开发简单介绍

    概览 终于到了真正接触IOS应用程序的时刻了,之前我们花了很多时间去讨论C语言.ObjC等知识,对于很多朋友而言开发IOS第一天就想直接看到成果,看到可以运行的IOS程序.但是这里我想强调一下,前面的 ...

  8. iOS开发多线程篇—多线程简单介绍

    iOS开发多线程篇—多线程简单介绍 一.进程和线程 1.什么是进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 比如同时打开QQ.Xcod ...

  9. iOS开发UI篇—UITabBarController简单介绍

    iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...

随机推荐

  1. Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement

    原因: 此异常的原因是由于mapper接口编译后在同一个目录下没有找到mapper映射文件而出现的.由于maven工程在默认情况下src/main/java目录下的mapper文件是不发布到targe ...

  2. Android Studio 常用应用

    1.在控制台的Logcat中输出测试语句 package com.example.lucky.helloworld; import android.support.v7.app.AppCompatAc ...

  3. C++_代码重用1-总览

    C++的主要目的是促进代码重用. 公有继承是实现这一目标的机制之一: 本身是另一个类的成员,这种方法称为包含.组合.层次化. 另一种方法是使用私有.保护继承. 通常包含.私有继承和保护继承用于实现ha ...

  4. LeetCode记录之7——Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Note:The ...

  5. SQL批量提交修改业务

    把你需要批量提交修改的东西在内存中修改完毕 然后执行以下代码 SqlConnection conn = new SqlConnection(ConnectionString);SqlDataAdapt ...

  6. 代理ip的使用以及多进程爬取

    一.代理皮的简单使用 简单的看一二例子即可 import requests #代理ip 高频的ip容易被封,所以使用ip代理 #免费代理 ip:www.goubanjia.com 快代理 西祠代理 h ...

  7. Web API 解决跨域问题

    一.跨域问题的由来 同源策略:出于安全考虑,浏览器会限制脚本中发起的跨站请求,浏览器要求JavaScript或Cookie只能访问同域下的内容. 正是由于这个原因,我们不同项目之间的调用就会被浏览器阻 ...

  8. Google Authenticator(谷歌身份验证器)

    <!DOCTYPE html>Google Authenticator(谷歌身份验证器) ] Google Authenticator(谷歌身份验证器) Google Authentica ...

  9. 记录树莓派静态IP修改

    1.操作:修改dhcpcd.conf文件 sudo nano /etc/dhcpcd.conf interface eth0 static ip_address=192.168.0.10/24 sta ...

  10. 6个Unity 开源项目分享!

    http://gad.qq.com/article/detail/38279?sessionUserType=BFT.PARAMS.249034.TASKID&ADUIN=991655778& ...