BootStrap+Angularjs+NgDialog實(shí)現(xiàn)模式對(duì)話框
本篇文章主要介紹了"angularjs+bootstrap+ngDialog實(shí)現(xiàn)模式對(duì)話框",對(duì)于Javascript教程感興趣的同學(xué)可以參考一下: 在完成一個(gè)后臺(tái)管理系統(tǒng)時(shí),需要用表顯示注冊(cè)用戶的信息。但是用戶地址太長(zhǎng)了,不好顯示。所以想做一個(gè)模式對(duì)話框,點(diǎn)擊詳細(xì)地址按鈕時(shí),彈出對(duì)話框,顯示地址。
效果如下圖:
通過(guò)查閱資料,選擇使用ngDialog來(lái)實(shí)現(xiàn),ngDialog是一個(gè)用于Angular.js應(yīng)用的模式對(duì)話框和彈出窗口。ngDialog非常?。?#63;2K),擁有簡(jiǎn)約的API,通過(guò)主題高度可定制的,具有唯一的依賴(lài)Angular.js。
ngDialog github地址: https://github.com/likeastore/ngDialog
ngDialog Demo : http://likeastore.github.io/ngDialog/
首先引入需要的ngdialog的js和css文件。
可通過(guò)CDN引入
<span style="font-size:18px;">//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.3.7/css/ngDialog.min.css //cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.3.7/css/ngDialog-theme-default.min.css //cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.3.7/css/ngDialog-theme-plain.min.css //cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.3.7/js/ngDialog.min.js</span>
在user.js里的controller中注入依賴(lài)
<span style="font-size:18px;">var userControllers = angular.module('userControllers',['ngDialog']); userControllers.controller('userController',['$scope','$http','ngDialog',function($scope,$http, ngDialog){ $scope.name = 'user'; $scope.user = ""; $scope.address = ""; //獲取用戶信息 $http.get('http://localhost:3000/users').success(function(data) { $scope.user = data; console.log($scope.user); }); //點(diǎn)擊詳細(xì)地址按鈕時(shí),跳出模式對(duì)話框 $scope.clickToAddress = function (address) { $scope.address = address; ngDialog.open({ template: 'views/test.html',//模式對(duì)話框內(nèi)容為test.html className: 'ngdialog-theme-plain', scope:$scope //將scope傳給test.html,以便顯示地址詳細(xì)信息 }); }; }])</span>
test.html(讀取scope中的address并顯示,表格樣式采用bootstrap )
<span style="font-size:18px;"><table class="table"> <thead> <tr> <th> 收件人姓名 </th> <td> {{address.name}} </td> </tr> <tr> <th> 收件地址 </th> <td> {{address.content}} </td> </tr> <tr> <th> 手機(jī)號(hào) </th> <td> {{address.phone}} </td> </tr> </thead> </table></span>
user.html (顯示用戶的信息,當(dāng)?shù)刂凡粸榭諘r(shí),顯示詳細(xì)地址按鈕,并點(diǎn)擊按鈕時(shí),調(diào)用controller中的clickToAddress函數(shù))
<span style="font-size:18px;"><div> <div class="panel panel-warning"> <div class="panel-heading"> 用戶管理 </div> <div class="row"> <div class="col-lg-8"></div> <div class="col-lg-4"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search for..." ng-model='search'> <span class="input-group-btn"> <button class="btn btn-default" type="button">Go!</button> </span> </div> </div> </div> <table class="table"> <thead> <th>姓名</th> <th>余額 <span class="glyphicon glyphicon-flash" aria-hidden="true"> </span></th> <th>頭像</th> <th>默認(rèn)地址</th> <th>操作</th> </thead> <tbody> <tr ng-repeat="user in user | filter : search" > <td>{{user.userName}}</td> <td>{{user.residualPayment}}</td> <td ng-if="user.url != 'undefined' ">{{user.url}}</td> <td ng-if="user.url == 'undefined' ">系統(tǒng)默認(rèn)頭像</td> <td ng-if="user.address.length == 0 ">暫無(wú)默認(rèn)地址</td> <td ng-if="user.address.length != 0"ng-repeat="address in user.address " ng-click="clickToAddress(address)"> <button type="button" class="btn btn-info navbar-btn">詳細(xì)地址</button> </td> <td> <button type="button" class="btn btn-warning navbar-btn" ng-click="remove(user._id)">刪除</button> </td> </tr> </tbody> </table> </div> </div></span>
以上所述是小編給大家介紹的BootStrap+Angularjs+NgDialog實(shí)現(xiàn)模式對(duì)話框,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
angular中ui calendar的一些使用心得(推薦)
下面小編就為大家?guī)?lái)一篇angular中ui calendar的一些使用心得(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11AngularJS實(shí)現(xiàn)的2048小游戲功能【附源碼下載】
這篇文章主要介紹了AngularJS實(shí)現(xiàn)的2048小游戲,可實(shí)現(xiàn)通過(guò)鍵盤(pán)W、S、A、D鍵控制上下左右移動(dòng)進(jìn)行游戲的功能,涉及AngularJS頁(yè)面元素動(dòng)態(tài)操作及數(shù)值運(yùn)算等相關(guān)操作技巧,并附帶源碼供讀者下載參考,需要的朋友可以參考下2018-01-01AngularJs html compiler詳解及示例代碼
本文主要介紹AngularJs html compiler的知識(shí)講解,這里整理了相關(guān)資料及相關(guān)示例代碼,有興趣的小伙伴可以參考下2016-09-09angular中兩種表單的區(qū)別(響應(yīng)式和模板驅(qū)動(dòng)表單)
這篇文章主要介紹了angular中兩種表單的區(qū)別(響應(yīng)式和模板驅(qū)動(dòng)表單),詳細(xì)的介紹了這兩種表單的實(shí)現(xiàn)以及區(qū)別,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2018-12-12angular4實(shí)現(xiàn)tab欄切換的方法示例
本篇文章主要介紹了angular4實(shí)現(xiàn)tab欄切換的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10將angular-ui的分頁(yè)組件封裝成指令的方法詳解
這篇文章主要給大家介紹了將angular-ui的分頁(yè)組件封裝成指令的方法,文中介紹的非常詳細(xì),相信會(huì)對(duì)大家的學(xué)習(xí)或者工作覺(jué)有一定的參考價(jià)值,需要的朋友下面來(lái)一起看看吧。2017-05-05angularjs 的數(shù)據(jù)綁定實(shí)現(xiàn)原理
本篇文章主要介紹了angularjs 的數(shù)據(jù)綁定實(shí)現(xiàn)原理,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07ionic4+angular7+cordova上傳圖片功能的實(shí)例代碼
ionic是一個(gè)垮平臺(tái)開(kāi)發(fā)框架,可通過(guò)web技術(shù)開(kāi)發(fā)出多平臺(tái)的應(yīng)用。這篇文章主要介紹了ionic4+angular7+cordova上傳圖片功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-06-06AngularJS基礎(chǔ) ng-mouseover 指令簡(jiǎn)單示例
本文主要介紹AngularJS ng-mouseover 指令,這里幫大家整理了AngularJS 指令的基礎(chǔ)知識(shí),并附代碼示例,有興趣的小伙伴可以參考下2016-08-08