当前位置: 首页 > news >正文

AngularJS Toaster

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>

转载于:https://www.cnblogs.com/youzhuxiaoyao/p/4953642.html

相关文章:

  • 静态网站生成器将会成为下一个大热门
  • 二维数组举例
  • 7月上旬全球域名新增13.5万个 环比减少近29%
  • sftp详细参数说明
  • Shane版详细设计书 文档模板
  • 简比:三大电商巨头的平台、支付、物流
  • VC++ 如何让ScrollView视图显示滚动条
  • android自定义View的用法
  • Unsupported major.minor version 51.0(jdk版本错误)
  • 最近读cocoaui源代码有感
  • 【原创】MySQL 5.5 新增SIGNAL异常处理
  • 在VMware Update Manager(VUM)里添加HP的补丁源
  • 命令和工具的宿主控件ToolBarControl控件
  • android ViewStub使用
  • [CareerCup] 14.5 Object Reflection 对象反射
  • 【React系列】如何构建React应用程序
  • CSS进阶篇--用CSS开启硬件加速来提高网站性能
  • Java,console输出实时的转向GUI textbox
  • JAVA_NIO系列——Channel和Buffer详解
  • JavaScript HTML DOM
  • JavaScript设计模式与开发实践系列之策略模式
  • JS函数式编程 数组部分风格 ES6版
  • Lsb图片隐写
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • Nodejs和JavaWeb协助开发
  • 高性能JavaScript阅读简记(三)
  • 如何使用 OAuth 2.0 将 LinkedIn 集成入 iOS 应用
  • 小而合理的前端理论:rscss和rsjs
  • 新版博客前端前瞻
  • 验证码识别技术——15分钟带你突破各种复杂不定长验证码
  • 走向全栈之MongoDB的使用
  • 回归生活:清理微信公众号
  • ###STL(标准模板库)
  • #pragam once 和 #ifndef 预编译头
  • #我与Java虚拟机的故事#连载11: JVM学习之路
  • (09)Hive——CTE 公共表达式
  • (rabbitmq的高级特性)消息可靠性
  • (二十五)admin-boot项目之集成消息队列Rabbitmq
  • (附源码)ssm高校升本考试管理系统 毕业设计 201631
  • (免费领源码)python#django#mysql公交线路查询系统85021- 计算机毕业设计项目选题推荐
  • (十八)devops持续集成开发——使用docker安装部署jenkins流水线服务
  • (转)eclipse内存溢出设置 -Xms212m -Xmx804m -XX:PermSize=250M -XX:MaxPermSize=356m
  • .net core 连接数据库,通过数据库生成Modell
  • .net on S60 ---- Net60 1.1发布 支持VS2008以及新的特性
  • ??在JSP中,java和JavaScript如何交互?
  • @cacheable 是否缓存成功_Spring Cache缓存注解
  • @html.ActionLink的几种参数格式
  • @RequestMapping 的作用是什么?
  • @SpringBootApplication 包含的三个注解及其含义
  • @Transactional类内部访问失效原因详解
  • [ACM] hdu 1201 18岁生日
  • [BT]BUUCTF刷题第9天(3.27)
  • [C语言]——函数递归
  • [Django 0-1] Core.Checks 模块
  • [Java]深入剖析常见排序