AngularJS Toaster使用詳解
AngularJS Toaster是一個(gè) AngularJS 提示框.基于angular v1.2.6 及以上和angular-animate. (推薦使用 /1.2.8/angular-animate.js, 因?yàn)楦甙姹緯?huì)有怪異閃爍.)
引入腳本
<link 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>
編寫(xiě)彈窗調(diào)用函數(shù)
angular.module('main', ['toaster', 'ngAnimate'])
.controller('myController', function($scope, toaster) {
$scope.pop = function(){
toaster.pop('success', "title", "text");
};
});
調(diào)用
<div ng-controller="myController"> <button ng-click="pop()">Show a Toaster</button> </div>
添加關(guān)閉按鈕
方式一: 全局的,為所有彈窗添加
<toaster-container toaster-options="{'close-button': true}"></toaster-container>
方式二:給close-btn 屬性傳遞一個(gè)對(duì)象
<toaster-container toaster-options="{'close-button':{ 'toast-warning': true, 'toast-error': false } }"></toaster-container>
表示warning類(lèi)型的彈窗顯示關(guān)閉按鈕,error類(lèi)型的則不顯示,不設(shè)置默認(rèn)為false不顯示
方式三 :在控制器里面設(shè)置:
toaster.pop({
type: 'error',
title: 'Title text',
body: 'Body text',
showCloseButton: true
});
這種設(shè)置會(huì)覆蓋頁(yè)面的屬性設(shè)置,不會(huì)污染其他的彈窗設(shè)置。
自定義關(guān)閉按鈕的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的渲染類(lèi)型) 可以接受 trustedHtml', ‘template', ‘templateWithData', ‘directive'四種類(lèi)型
trustedHtml:使用此類(lèi)型 toaster會(huì)調(diào)用$sce.trustAsHtml(toast.body)如果解析成功將會(huì)通過(guò)ng-bind-html指令被綁定到toaster,失敗會(huì)拋出一個(gè)異常
作為模板處理
例如:
$scope.pop = function(){
toaster.pop({
type: 'error',
title: 'Title text',
body: 'cont.html',
showCloseButton: true,
bodyOutputType:'template',
closeHtml: '<span>wqeqwe</span>'
});
};
作為指令來(lái)處理
toaster.pop({
type: 'info',
body: 'bind-unsafe-html',
bodyOutputType: 'directive'
});
.directive('bindUnsafeHtml', [function () {
return {
template: "<span style='color:orange'>Orange directive text!</span>"
};
}])
帶數(shù)據(jù)的指令
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>
回調(diào)函數(shù),當(dāng)彈窗被移除的時(shí)候調(diào)用,可以用于鏈?zhǔn)秸{(diào)用彈窗
toaster.pop({
title: 'A toast',
body: 'with a callback',
onHideCallback: function () {
toaster.pop({
title: 'A toast',
body: 'invoked as a callback'
});
}
});
設(shè)置彈窗位置
位置信息可以去css文件里面看需要什么位置,直接把屬性值改成相應(yīng)class就行,如果沒(méi)有符合的就自己手動(dòng)添加一個(gè)到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使用詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- angular2中router路由跳轉(zhuǎn)navigate的使用與刷新頁(yè)面問(wèn)題詳解
- Angular2學(xué)習(xí)筆記——詳解路由器模型(Router)
- 詳解angular2實(shí)現(xiàn)ng2-router 路由和嵌套路由
- Angular2 之 路由與導(dǎo)航詳細(xì)介紹
- AngularJs 彈出模態(tài)框(model)
- Angular彈出模態(tài)框的兩種方式
- AngularJS $modal彈出框?qū)嵗a
- angularjs創(chuàng)建彈出框?qū)崿F(xiàn)拖動(dòng)效果
- Angular 2使用路由自定義彈出組件toast操作示例
相關(guān)文章
Angular中使用$watch監(jiān)聽(tīng)object屬性值的變化(詳解)
下面小編就為大家?guī)?lái)一篇Angular中使用$watch監(jiān)聽(tīng)object屬性值的變化(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
將angular-ui的分頁(yè)組件封裝成指令的方法詳解
這篇文章主要給大家介紹了將angular-ui的分頁(yè)組件封裝成指令的方法,文中介紹的非常詳細(xì),相信會(huì)對(duì)大家的學(xué)習(xí)或者工作覺(jué)有一定的參考價(jià)值,需要的朋友下面來(lái)一起看看吧。2017-05-05
Angular限制input框輸入金額(是小數(shù)的話只保留兩位小數(shù)點(diǎn))
最近做項(xiàng)目遇到這樣的需求輸入框要求輸入金額,只能輸入數(shù)字,可以是小數(shù),必須保留小數(shù)點(diǎn)后兩位。下面分為兩部分代碼給大家介紹實(shí)現(xiàn)代碼,需要的的朋友參考下吧2017-07-07
AngularJS入門(mén)之動(dòng)畫(huà)
AngularJS中ngAnimate模塊支持動(dòng)畫(huà)效果,但是ngAnimate模塊并未包含在AngularJS核心庫(kù)中,因此需要使用ngAnimate需要在定義Module時(shí)聲明對(duì)其的引用。下面通過(guò)本文我們來(lái)看看AngularJS動(dòng)畫(huà)的詳細(xì)介紹。2016-07-07
AngularJS 打開(kāi)新的標(biāo)簽頁(yè)實(shí)現(xiàn)代碼
本文通過(guò)實(shí)例代碼給大家介紹了angularJS 打開(kāi)新的標(biāo)簽頁(yè)方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-09-09
AngularJS $on、$emit和$broadcast的使用
本文主要介紹AngularJS $on、$emit和$broadcast的使用,這里整理了詳細(xì)的資料及簡(jiǎn)單示例代碼有興趣的小伙伴可以參考下2016-09-09
詳解angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程
本篇文章主要介紹了詳解angularjs實(shí)現(xiàn)echart圖表效果最簡(jiǎn)潔教程,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11

