AngularJS模態(tài)框模板ngDialog的使用詳解
項(xiàng)目開始的時(shí)候我們用的對(duì)話框是AngularJS的$modal模態(tài)框,但是后來發(fā)現(xiàn)$modal打開的對(duì)話框是相對(duì)頁面靜止的,如果對(duì)話框是一個(gè)很長的表單,這樣體驗(yàn)度就不是很好了,還有$modal傳$scope不是很靈活的原因,后來就改用的$ngDialog.
官方的API在這里:https://www.npmjs.com/package/ng-dialog
首先確定你的項(xiàng)目已經(jīng)安裝了$ngDialog需要的相關(guān)文件。
接下來一個(gè)簡單的demo
del.html內(nèi)容如下,就是你的對(duì)話框內(nèi)容,這里比較簡單,只是一個(gè)確認(rèn)對(duì)話框
<meta charset="UTF-8"> <div class="modal-header"> <h4 class="modal-title">刪除</h4> </div> <div class="modal-body"> <form autocomplete="off" class="file-brief file-brief-show form-validation" name="ObsForm" id="form-new-style"> <div class="col-sm-12 m-t-xs m-b-xs "> <div class="form-group"> <label>您確認(rèn)要?jiǎng)h除嗎?</label> </div> </div> </form> </div> <div class="modal-footer"> <button type="submit" class="btn" ng-click="confirm()" >確定</button> <button type="button" class="btn" ng-click="cancel()">取消</button> </div>
在你的Controller里添加你的方法:
$scope.del = function () { ngDialog.open({ template: '/del.html', className: 'ngdialog-theme-default', scope: $scope, controller: function ($scope) { ... $scope.confirm = function () { ... }; $scope.cancel = function () { $scope.closeThisDialog(); }; } }); };
這里template里是一個(gè)路徑,其實(shí)如果對(duì)話框簡單的話可以在template里直接寫<div>內(nèi)容,只是要加一個(gè)屬性:plain:true,
對(duì)話框的高度寬度都可以自定義,width:500,//絕對(duì)寬度?;蛘遷idth:‘%50' //相對(duì)寬度
針對(duì)以上兩點(diǎn),示例:
$scope.delBucket = function () { ngDialog.open({ template: '<div class="modal-header"><h4 class="modal-title">刪除Bucket</h4></div>' + '<div class="modal-footer"><button type="submit" class="btn" ng-click="confirm()" >確定</button>'+ '<button type="button" class="btn" ng-click="cancel()">取消</button></div>', plain:true, className: 'ngdialog-theme-default', width:600, scope: $scope, controller: function ($scope) { ... $scope.confirm = function () { ... }; $scope.cancel = function () { $scope.closeThisDialog(); }; } }); };
以上只是一個(gè)簡單的示例,官方文檔上還有通過id打開對(duì)話框,打開一個(gè)確認(rèn)對(duì)話框等相關(guān)詳細(xì)介紹。
另外有一篇對(duì)$ngDialog介紹非常詳細(xì)的文章,基本上就是把官方API翻譯過來了。
附上文章鏈接http://www.dbjr.com.cn/article/139899.htm
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Angularjs中的驗(yàn)證input輸入框只能輸入數(shù)字和小數(shù)點(diǎn)的寫法(推薦)
這篇文章主要介紹了Angularjs中的驗(yàn)證input輸入框只能輸入數(shù)字和小數(shù)點(diǎn)的寫法,需要的朋友可以參考下2017-08-08利用VS Code開發(fā)你的第一個(gè)AngularJS 2應(yīng)用程序
這篇文章主要給大家介紹了關(guān)于利用VS Code如何開發(fā)你的第一個(gè)AngularJS 2應(yīng)用程序的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友下面來一起看看吧。2017-12-12angularJs中跳轉(zhuǎn)到指定的錨點(diǎn)實(shí)例($anchorScroll)
今天小編就為大家分享一篇angularJs中跳轉(zhuǎn)到指定的錨點(diǎn)實(shí)例($anchorScroll),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08angular2實(shí)現(xiàn)統(tǒng)一的http請(qǐng)求頭方法
今天小編就為大家分享一篇angular2實(shí)現(xiàn)統(tǒng)一的http請(qǐng)求頭方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08AngularJS實(shí)現(xiàn)在ng-Options加上index的解決方法
這篇文章主要介紹了AngularJS實(shí)現(xiàn)在ng-Options加上index的解決方法,結(jié)合實(shí)例形式分析了AngularJS在ngOptions添加索引的操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-11-11Angular4項(xiàng)目中添加i18n國際化插件ngx-translate的步驟詳解
這篇文章主要跟大家介紹了關(guān)于Angular4項(xiàng)目中添加i18n國際化插件ngx-translate的步驟,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-07-07