• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

AngularJS Toaster使用详解

angularjs 搞代码 4年前 (2021-12-31) 29次浏览 已收录 0个评论

AngularJS Toaster是一个 AngularJS 提示框.基于angular v1.2.6 及以上和angular-animate.这篇文章主要介绍了AngularJS Toaster使用详解,需要的朋友可以参考下

AngularJS Toaster是一个 AngularJS 提示框.基于angular v1.2.6 及以上和angular-animate. (推荐使用 /1.2.8/angular-animate.js, 因为高版本会有怪异闪烁.)

引入脚本

 

用法1:

添加指令

 

编写弹窗调用函数

 angular.module('main', ['toaster', 'ngAnimate']) .controller('myController', function($s<a style="color:transparent">来源gao*daima.com搞@代#码网</a>cope, toaster) { $scope.pop = function(){ toaster.pop('success', "title", "text"); }; });

调用

 <div> <button>Show a Toaster</button></div>

添加关闭按钮

方式一: 全局的,为所有弹窗添加

 

方式二:给close-btn 属性传递一个对象

 

表示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.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.pop({ title: 'A toast', body: 'with a callback', onHideCallback: function () { toaster.pop({ title: 'A toast', body: 'invoked as a callback' }); } });

设置弹窗位置

位置信息可以去css文件里面看需要什么位置,直接把属性值改成相应class就行,如果没有符合的就自己手动添加一个到toaster.css文件然后把名字赋值给属性就行

 

以上就是AngularJS Toaster使用详解的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:AngularJS Toaster使用详解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址