温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

angularJS如何实现模态框$modal

发布时间:2021-07-20 14:36:36 来源:亿速云 阅读:132 作者:小新 栏目:web开发

小编给大家分享一下angularJS如何实现模态框$modal,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

1.引入$modal模块

如:angular.module('ModalCtrl',['$modal' ,'$scope' , function($modal ,$scope ){ }]);

2.执行调模态框 函数

$scope.editModule = function(type, size, id) { 
  $scope.id = id; 
  var modalInstance = $modal.open({ 
    templateUrl: 'tpl/weichat_modulebaseinfo.html', //template:'html元素模板', 
    controller: 'EditModuleCtrl', // 初始化模态范围 
    size: size, //大小配置 
    scope: '一个作用域为模态的内容使用($modal会创建一个当前作用域的子作用域,scope可有可无)默认为$rootScope', 
    resolve: { 
      items: function() { 
        return $scope.id; //向模态框控制器中传值 
      } 
    } 
    background: '', //控制背景,true(有) or false(无),static背景存在,但是点击模态窗口之外,模态窗不关闭 
    keyboard: '', //按下Esc时,模态对话框是否关闭,默认为ture 
    windowClass: '' //指定一个class并被添加到模态窗口中 
 
  }); 
 
  modalInstance.result.then(function(selectedItem) { //模态框关闭后返回函数,selectedItem为返回值 
 
  }) 
}

3.创建模态框控制器

app.controller('EditModuleCtrl', ['$scope', '$modalInstance', 'BookService', '$stateParams', 'items', function($scope, $modalInstance, BookService, $stateParams, items) { //依赖于modalInstance 
    //items为传过来的值 
    $scope.modalBack = function() { 
      //执行模态框内部操作 
    } 
 
    $scope.ok = function() { 
      $modalInstance.close($scope.textid); //关闭并返回当前选项 
    }; 
    $scope.cancel = function() { 
      $modalInstance.dismiss('cancel'); // 退出不执行任何操作 
    } 
  }])

以上是“angularJS如何实现模态框$modal”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI