AngularJS Toaster使用詳解
AngularJS Toaster是一個 AngularJS 提示框.基于angular v1.2.6 及以上和angular-animate. (推薦使用 /1.2.8/angular-animate.js, 因為高版本會有怪異閃爍.)
引入腳本
<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>
編寫彈窗調(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 屬性傳遞一個對象
<toaster-container toaster-options="{'close-button':{ 'toast-warning': true, 'toast-error': false } }"></toaster-container>
表示warning類型的彈窗顯示關(guān)閉按鈕,error類型的則不顯示,不設(shè)置默認為false不顯示
方式三 :在控制器里面設(shè)置:
toaster.pop({ type: 'error', title: 'Title text', body: 'Body text', showCloseButton: true });
這種設(shè)置會覆蓋頁面的屬性設(shè)置,不會污染其他的彈窗設(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的渲染類型) 可以接受 trustedHtml', ‘template', ‘templateWithData', ‘directive'四種類型
trustedHtml:使用此類型 toaster會調(diào)用$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>" }; }])
帶數(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ù),當彈窗被移除的時候調(diào)用,可以用于鏈式調(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就行,如果沒有符合的就自己手動添加一個到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使用詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
AngularJS應(yīng)用開發(fā)思維之依賴注入3
這篇文章主要為大家詳細介紹了AngularJS應(yīng)用開發(fā)思維之依賴注入第三篇,感興趣的小伙伴們可以參考一下2016-08-08掌握Queries設(shè)計模式優(yōu)化Angular應(yīng)用開發(fā)技巧
這篇文章主要介紹了掌握Queries設(shè)計模式優(yōu)化Angular應(yīng)用開發(fā)的技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10Angular-Ui-Router+ocLazyLoad動態(tài)加載腳本示例
本篇文章主要介紹了Angular-Ui-Router+ocLazyLoad動態(tài)加載腳本示例,可以提高加載速度,使用戶體驗更好,有興趣的可以了解一下。2017-03-03詳解Angular調(diào)試技巧之報錯404(not found)
本篇文章主要介紹了詳解Angular調(diào)試技巧之報錯404(not found),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01AngularJS動態(tài)添加數(shù)據(jù)并刪除的實例
下面小編就為大家分享一篇AngularJS動態(tài)添加數(shù)據(jù)并刪除的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02