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

首頁 > 語言 > JavaScript > 正文

AngularJS中使用ngModal模態框實例

2024-05-06 15:16:39
字體:
來源:轉載
供稿:網友

在AngularJS中使用模態框需要引用的文件:

    angular.js 1.5.5 ui.bootstrap-tpls.js 0.11.2 bootstrap.css 3.3.7

需要注意版本要一致,高版本的不支持這種方法,會出錯

將需要彈出的模態框的內容寫在 script 標簽中,指明屬性,放在頁面中

<script type="text/ng-template" id="modal.html"> <div>  <div class="modal-header">    <h3 class="modal-title" align="center">      標題信息    </h3>  </div>  <div class="modal-body">    <div align="center">      模態框內容    </div>  </div>  <div class="modal-footer">    <button class="btn btn-primary" ng-click="ok()">      確認    </button>    <button class="btn btn-warning" ng-click="cancel()">      退出    </button>  </div></div></script>

在App和Controller中注入模態框

var app = angular.module('app', ['ui.bootstrap']);app.controller('modalController', function($scope, $rootScope,$modal) {  $scope.openModel = function() {      var modalInstance = $modal.open({        templateUrl : 'modal.html',//script標簽中定義的id        controller : 'modalCtrl',//modal對應的Controller        resolve : {          data : function() {//data作為modal的controller傳入的參數             return data;//用于傳遞數據          }        }      })    }}//模態框對應的Controllerapp.controller('modalCtrl', function($scope, $modalInstance, data) {  $scope.data= data;  //在這里處理要進行的操作    $scope.ok = function() {    $modalInstance.close();  };  $scope.cancel = function() {    $modalInstance.dismiss('cancel');  }});

添加事件觸發顯示模態框

<button ng-click="openModal()">打開模態框</button>

html

<!DOCTYPE html><html ng-app="app" ng-controller="modalController"><head>  <title>ng-model模態框</title></head><link  rel="external nofollow" rel="stylesheet"><body><button ng-click="openModal()">打開模態框</button><script type="text/ng-template" id="modal.html">   <div>    <div class="modal-header">      <h3 class="modal-title" align="center">        標題信息      </h3>    </div>    <div class="modal-body">      <div align="center">        模態框內容 <br>        {{data}}      </div>    </div>    <div class="modal-footer">      <button class="btn btn-primary" ng-click="ok()">        確認      </button>      <button class="btn btn-warning" ng-click="cancel()">        退出      </button>    </div>  </div></script><script src="https://cdn.bootcss.com/angular.js/1.5.5/angular.min.js"></script><script src="https://cdn.bootcss.com/angular-ui-bootstrap/0.11.2/ui-bootstrap-tpls.min.js"></script><script type="text/javascript">  var app = angular.module('app', ['ui.bootstrap']);  app.controller('modalController', function($scope, $rootScope, $modal) {    var data = "通過modal傳遞的數據";    $scope.openModal = function() {        var modalInstance = $modal.open({          templateUrl : 'modal.html',//script標簽中定義的id          controller : 'modalCtrl',//modal對應的Controller          resolve : {            data : function() {//data作為modal的controller傳入的參數               return data;//用于傳遞數據            }          }        })      }  })   //模態框對應的Controller   app.controller('modalCtrl', function($scope, $modalInstance, data) {     $scope.data= data;     //在這里處理要進行的操作     $scope.ok = function() {       $modalInstance.close();     };     $scope.cancel = function() {       $modalInstance.dismiss('cancel');     }  });</script></body></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 方山县| 沙洋县| 延津县| 鲁山县| 无为县| 柏乡县| 比如县| 连云港市| 仁寿县| 涿州市| 黄浦区| 定安县| 鄢陵县| 静海县| 高陵县| 分宜县| 嫩江县| 朔州市| 石阡县| 玛曲县| 永德县| 龙南县| 宁陕县| 沙河市| 宁乡县| 珠海市| 日喀则市| 上栗县| 延吉市| 苍溪县| 平塘县| 象州县| 龙川县| 神农架林区| 江山市| 年辖:市辖区| 遵义县| 通化市| 通化市| SHOW| 芷江|