国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

BootStrap+Angularjs+NgDialog實(shí)現(xiàn)模式對(duì)話框

2019-11-20 09:09:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本篇文章主要介紹了"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非常小(?2K),擁有簡(jiǎn)約的API,通過(guò)主題高度可定制的,具有唯一的依賴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中注入依賴

<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.htmlclassName: '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ì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 晋中市| 孟连| 乐陵市| 灵山县| 雅江县| 恩平市| 阳曲县| 商河县| 山丹县| 耿马| 五常市| 宝清县| 白山市| 宣化县| 屏东市| 册亨县| 三亚市| 涡阳县| 栾城县| 蓝田县| 河南省| 社会| 铅山县| 双流县| 柯坪县| 汾西县| 宝应县| 苗栗县| 阿拉尔市| 河南省| 吉安县| 双牌县| 怀集县| 桂平市| 大安市| 工布江达县| 义马市| 民勤县| 饶河县| 安徽省| 孝感市|