angularJS模態(tài)框$modal實(shí)例代碼
1.引入$modal模塊
如:angular.module('ModalCtrl',['$modal' ,'$scope' , function($modal ,$scope ){ }]);
2.執(zhí)行調(diào)模態(tài)框 函數(shù)
$scope.editModule = function(type, size, id) {
$scope.id = id;
var modalInstance = $modal.open({
templateUrl: 'tpl/weichat_modulebaseinfo.html', //template:'html元素模板',
controller: 'EditModuleCtrl', // 初始化模態(tài)范圍
size: size, //大小配置
scope: '一個(gè)作用域?yàn)槟B(tài)的內(nèi)容使用($modal會(huì)創(chuàng)建一個(gè)當(dāng)前作用域的子作用域,scope可有可無(wú))默認(rèn)為$rootScope',
resolve: {
items: function() {
return $scope.id; //向模態(tài)框控制器中傳值
}
}
background: '', //控制背景,true(有) or false(無(wú)),static背景存在,但是點(diǎn)擊模態(tài)窗口之外,模態(tài)窗不關(guān)閉
keyboard: '', //按下Esc時(shí),模態(tài)對(duì)話框是否關(guān)閉,默認(rèn)為ture
windowClass: '' //指定一個(gè)class并被添加到模態(tài)窗口中
});
modalInstance.result.then(function(selectedItem) { //模態(tài)框關(guān)閉后返回函數(shù),selectedItem為返回值
})
}
3.創(chuàng)建模態(tài)框控制器
app.controller('EditModuleCtrl', ['$scope', '$modalInstance', 'BookService', '$stateParams', 'items', function($scope, $modalInstance, BookService, $stateParams, items) { //依賴于modalInstance
//items為傳過(guò)來(lái)的值
$scope.modalBack = function() {
//執(zhí)行模態(tài)框內(nèi)部操作
}
$scope.ok = function() {
$modalInstance.close($scope.textid); //關(guān)閉并返回當(dāng)前選項(xiàng)
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel'); // 退出不執(zhí)行任何操作
}
}])
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
AngularJS使用ng-repeat指令實(shí)現(xiàn)下拉框
這篇文章主要介紹了AngularJS使用ng-repeat指令實(shí)現(xiàn)下拉框的相關(guān)資料,非常不錯(cuò),感興趣的朋友一起看下吧,需要的朋友可以參考下2016-08-08
AngularJS表格樣式簡(jiǎn)單設(shè)置方法示例
這篇文章主要介紹了AngularJS表格樣式簡(jiǎn)單設(shè)置方法,結(jié)合實(shí)例形式分析了AngularJS結(jié)合bootstrap針對(duì)表格樣式的相關(guān)設(shè)置技巧,需要的朋友可以參考下2017-03-03
Angular中封裝fancyBox(圖片預(yù)覽)遇到問(wèn)題小結(jié)
這篇文章主要介紹了Angular中封裝fancyBox(圖片預(yù)覽)遇到的問(wèn)題小結(jié),需要的朋友可以參考下2017-09-09
詳解AngularJS通過(guò)ocLazyLoad實(shí)現(xiàn)動(dòng)態(tài)(懶)加載模塊和依賴
本篇文章主要介紹了詳解AngularJS通過(guò)ocLazyLoad實(shí)現(xiàn)動(dòng)態(tài)(懶)加載模塊和依賴 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
AngularJS封裝$http.post()實(shí)例詳解
這篇文章主要介紹了 AngularJS封裝$http.post()實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05
AngularJS基礎(chǔ) ng-mouseleave 指令詳解
本文主要介紹AngularJS ng-mouseleave 指令,這里幫大家整理了ng-mouseleave指令的詳細(xì)資料,并附有代碼示例,有需要的小伙伴可以參考下2016-08-08

