javascript - How to use bootstrap modal window with angularjs? - Stack Overflow

I want to use bootstrap pop window for some user confirmation but i got stuck initially here by using b

I want to use bootstrap pop window for some user confirmation but i got stuck initially here by using bootstrap with angularjs , Any idea what is implemented wrong below to have bootstrap modal window or any better approach to use bootstrap modal window with angularjs ? I do not see any error in console.

app.js

angular.module('App', [
    'ui.router',
    'ui.bootstrap']).config(function ($stateProvider, $httpProvider, $urlRouterProvider) {

//config code here ..
});

ctrl.js

angular.module('App').controller('modalController',function($scope,$uibModal){
    $scope.openModal = function () {
            console.log('opening pop up');
            var modalInstance = $uibModal.open({
                templateUrl: 'web/global/modal.html',
            });
        }
});

home.html

<button class="btn btn-warning" ng-click="openModal()">Simple Popup</button>

I want to use bootstrap pop window for some user confirmation but i got stuck initially here by using bootstrap with angularjs , Any idea what is implemented wrong below to have bootstrap modal window or any better approach to use bootstrap modal window with angularjs ? I do not see any error in console.

app.js

angular.module('App', [
    'ui.router',
    'ui.bootstrap']).config(function ($stateProvider, $httpProvider, $urlRouterProvider) {

//config code here ..
});

ctrl.js

angular.module('App').controller('modalController',function($scope,$uibModal){
    $scope.openModal = function () {
            console.log('opening pop up');
            var modalInstance = $uibModal.open({
                templateUrl: 'web/global/modal.html',
            });
        }
});

home.html

<button class="btn btn-warning" ng-click="openModal()">Simple Popup</button>
Share Improve this question asked Jul 25, 2016 at 19:02 hussainhussain 7,14121 gold badges87 silver badges165 bronze badges 1
  • 1 Is the path to your template correct: 'web/global/modal.html' ? – AJ Meyghani Commented Jul 25, 2016 at 19:07
Add a ment  | 

1 Answer 1

Reset to default 4

ANGULAR UI BOOTSTRAP :


WORKING EXAMPLE:

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function($scope, $modal, $log) {

  $scope.items = ['item1', 'item2', 'item3'];

  $scope.animationsEnabled = true;

  $scope.open = function(size) {

    var modalInstance = $modal.open({
      animation: $scope.animationsEnabled,
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      size: size,
      resolve: {
        items: function() {
          return $scope.items;
        }
      }
    });

    modalInstance.result.then(function(selectedItem) {
      $scope.selected = selectedItem;
    }, function() {
      $log.info('Modal dismissed at: ' + new Date());
    });
  };

  $scope.toggleAnimation = function() {
    $scope.animationsEnabled = !$scope.animationsEnabled;
  };

});

// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function($scope, $modalInstance, items) {

  $scope.items = items;
  $scope.selected = {
    item: $scope.items[0]
  };

  $scope.ok = function() {
    $modalInstance.close($scope.selected.item);
  };

  $scope.cancel = function() {
    $modalInstance.dismiss('cancel');
  };
});
<!doctype html>
<html ng-app="ui.bootstrap.demo">

<head>
  <script src="//ajax.googleapis./ajax/libs/angularjs/1.4.3/angular.js"></script>
  <script src="//ajax.googleapis./ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
  <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.3.js"></script>
  <link href="//netdna.bootstrapcdn./bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

  <div ng-controller="ModalDemoCtrl">
    <script type="text/ng-template" id="myModalContent.html">
      <div class="modal-header">
        <h3 class="modal-title">I'm a modal!</h3>
      </div>
      <div class="modal-body">
        <ul>
          <li ng-repeat="item in items">
            <a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
          </li>
        </ul>
        Selected: <b>{{ selected.item }}</b>
      </div>
      <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
        <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
      </div>
    </script>

    <button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
    <button type="button" class="btn btn-default" ng-click="open('lg')">Large modal</button>
    <button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button>
    <button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button>
    <div ng-show="selected">Selection from a modal: {{ selected }}</div>
  </div>
</body>

</html>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744750681a4591575.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信