hussain hussain - 5 months ago 67
AngularJS Question

How to use bootstrap modal window with angularjs?

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.


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

//config code here ..


$scope.openModal = function () {
console.log('opening pop up');
var modalInstance = ${
templateUrl: 'web/global/modal.html',


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




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;

  $ = function(size) {

    var modalInstance = ${
      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() {
      $'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() {

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

  <script src="//"></script>
  <script src="//"></script>
  <script src="//"></script>
  <link href="//" rel="stylesheet">


  <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 class="modal-body">
          <li ng-repeat="item in items">
            <a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
        Selected: <b>{{ selected.item }}</b>
      <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>

    <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>