twitter bootstrap - AngularJS: External Modal Templates -


i read agularjs - include external html file modals, didn't include code or explanation , pointed docs i've read. so, go more detail.

i have main html file spa (single page application). want use modals more detailed views.

<html> <head>     <meta charset='utf-8'>     <script src="js/angular.js"></script>     <script src="js/angular-ui-bootstrap-modal.js"></script>     <script src="js/app.js"></script>     <link rel="stylesheet" href="css/bootstrap.css"> </head> <body ng-app="myapp" ng-controller="myctrl">  <button class="btn" ng-click="open()">open modal</button>  <!-- want in separate html file -->  <div modal="showmodal" close="cancel()">     <div class="modal-header">         <h4>modal dialog</h4>     </div>     <div class="modal-body">         <p>example paragraph text.</p>     </div>     <div class="modal-footer">         <button class="btn btn-success" ng-click="ok()">okay</button>         <button class="btn" ng-click="cancel()">cancel</button>     </div> </div>  <!-- -->  </body> </html> 

and app.js file:

var app = angular.module("myapp", ["ui.bootstrap.modal"]);  app.controller("myctrl", function($scope) {    $scope.open = function() {     $scope.showmodal = true;   };    $scope.ok = function() {     $scope.showmodal = false;   };    $scope.cancel = function() {     $scope.showmodal = false;   };  }); 

what need add app.js in order able display external html files modals on main html page?

i've done plnkr explain better

to open modal defined in dedicated html template :

1. following declared in controller responsible button opening modal :

$modal.open({   templateurl: 'mymodaltemplate.html',   controller: 'mymodalcontroller' }); 

2. in controller of modal :

$scope.ok = function () {     $modalinstance.close(); };  $scope.cancel = function () {     $modalinstance.dismiss('cancel'); }; 

see ui bootstrap doc


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -