BootStrap+Angularjs+NgDialog實現(xiàn)模式對話框
本篇文章主要介紹了"angularjs+bootstrap+ngDialog實現(xiàn)模式對話框",對于Javascript教程感興趣的同學(xué)可以參考一下: 在完成一個后臺管理系統(tǒng)時,需要用表顯示注冊用戶的信息。但是用戶地址太長了,不好顯示。所以想做一個模式對話框,點擊詳細(xì)地址按鈕時,彈出對話框,顯示地址。
效果如下圖:


通過查閱資料,選擇使用ngDialog來實現(xiàn),ngDialog是一個用于Angular.js應(yīng)用的模式對話框和彈出窗口。ngDialog非常?。?#63;2K),擁有簡約的API,通過主題高度可定制的,具有唯一的依賴Angular.js。
ngDialog github地址: https://github.com/likeastore/ngDialog
ngDialog Demo : http://likeastore.github.io/ngDialog/
首先引入需要的ngdialog的js和css文件。
可通過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);
});
//點擊詳細(xì)地址按鈕時,跳出模式對話框
$scope.clickToAddress = function (address) {
$scope.address = address;
ngDialog.open({ template: 'views/test.html',//模式對話框內(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>
手機號
</th>
<td>
{{address.phone}}
</td>
</tr>
</thead>
</table></span>
user.html (顯示用戶的信息,當(dāng)?shù)刂凡粸榭諘r,顯示詳細(xì)地址按鈕,并點擊按鈕時,調(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 ">暫無默認(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實現(xiàn)模式對話框,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
AngularJS+Node.js實現(xiàn)在線聊天室
隨著互聯(lián)網(wǎng)和信息技術(shù)的發(fā)展,如何快速構(gòu)建高效、強大的動態(tài)網(wǎng)站成為很多人研究的熱點。該文將結(jié)合AngularJS和Node.js構(gòu)建一個在線聊天室,體現(xiàn)AngularJs和Node.js整合的優(yōu)點。2015-08-08
AngularJS學(xué)習(xí)第一篇 AngularJS基礎(chǔ)知識
這篇文章主要介紹了AngularJS學(xué)習(xí)第一篇,分享了有關(guān)AngularJS的基礎(chǔ)知識,主要包括指令、過濾器等,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02
詳解Angular.js數(shù)據(jù)綁定時自動轉(zhuǎn)義html標(biāo)簽及內(nèi)容
本篇文章主要介紹了詳解Angular.js數(shù)據(jù)綁定時自動轉(zhuǎn)義html標(biāo)簽及內(nèi)容 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03
angularjs實現(xiàn)上拉加載和下拉刷新數(shù)據(jù)功能
本篇文章主要介紹了angularjs實現(xiàn)上拉加載和下拉刷新數(shù)據(jù)功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
Angular發(fā)布1.5正式版,專注于向Angular 2的過渡
Angular團隊最近發(fā)布了Angular 1.5的正式版,該版本實現(xiàn)了一次重大的升級,它讓仍在使用1.X版本的開發(fā)者將能夠更容易地過渡到Angular 2的開發(fā)2016-02-02

