Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This is my code

var app = angular.module('drinks-app', ['ui.bootstrap']);

app.controller('MainCtrl', function($scope, Drink)  {
  'use strict';

  Drink().then(function(drinks) {
    $scope.drinks = drinks;
  });

  $scope.deleteItem = function(item) {
    console.log("deleting item " + item.name);
  };
});


app.factory('Drink', function($http) {
  'use strict';
  return function() {
    return $http.get('drinks.json').then(function(response, status) {
      return response.data;
    });
  };
});

app.directive('ngConfirm', function($modal, $parse) {
  return {
    // So the link function is run before ngClick's, which has priority 0
    priority: -1,

    link: function(scope, element, attrs) {
      element.on('click', function(e) {
        // Don't run ngClick's handler
        e.stopImmediatePropagation();
  
        $modal.open({
          templateUrl: 'ng-delete-template',
          controller: 'ngConfirmController',
          resolve: {
            message: function() {
              return attrs.ngConfirm;
            }
          }
        }).result.then(function() {
          // Pass original click as '$event', just like ngClick
          $parse(attrs.ngClick)(scope, {$event: e});
        });
      });
    }
  };
});

app.controller('ngConfirmController', function($scope, $modalInstance, message) {
  $scope.message = message;
  
  $scope.yes = function() {
    $modalInstance.close();
  };
  
  $scope.no = function() {
    $modalInstance.dismiss();
  };
});
<!DOCTYPE html>
<html ng-app="drinks-app">

  <head>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
    <link rel="stylesheet" href="style.css">
 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.0/ui-bootstrap.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.0/ui-bootstrap-tpls.min.js"></script>
    <script src="script.js"></script>
    <script type="text/ng-template" id="ng-delete-template">
      <div class="modal-body">
        <p>{{message}}</p>
      </div>
      <div class="modal-footer">
        <button class="btn btn-link pull-left" ng-click="no()">No</button>
        <button class="btn btn-primary pull-right" ng-click="yes()">Yes</button>
      </div>
    </script>
    <script type="text/ng-template" id="ng-add-template">
      <div class="modal-body">
      <select >
      <option value="emp" >emplopyee</option>
      </select>
            </div>
      <div class="modal-footer">
        <button class="btn btn-link pull-left">ADD</button>
        
      </div>
    </script>
  </head>

  <body ng-controller="MainCtrl">
    <div class="container">
 
      
      <button class="btn btn-small" type="button" ng-click="deleteItem(drink)" ng-confirm="Are you sure you want to delete '{{drink.name}}'">Delete</button>
      <button class="btn btn-small" type="button" ng-click="deleteItem(drink)" ng-confirm="Are you sure you want to delete '{{drink.name}}'">Add</button>
    </div>
  </body>
</html>

Thsi is my plunker : http://plnkr.co/edit/Gm9lFsGb099w6kCMQoVY?p=preview

In the above code use ui.bootstrap for model popup (delete), now i want to use same model popup for display another template . that means i have two dropdown display list of employees and departments. In previous popup display delete information text only and templateUrl :- assign delete.html page statically. now i want to assign dynamic path to templateUrl in AngularJs model popup

share|improve this question
up vote 3 down vote accepted

You could pass template name from directive attribute & then place it over $modal.open's templateUrl option like

<button template-path="abc.html" class="btn btn-small" type="button" 
  ng-click="deleteItem(drink)" ng-confirm="Are you sure you want to delete '{{drink.name}}'">
  Delete
</button>

Then in directive

templateUrl: attrs.templatePath || 'ng-confirm-template',

Demo Here

share|improve this answer
    
Thank You @Pankaj, That is working fine , But i have data from my controller that data not binding to dropdowns in model popup – durga siva kishore mopuru Mar 24 at 9:55
    
In that case I'll suggest you to have isolate scope for directive and pass dropdown data directive..that will pass that to directive – Pankaj Parkar Mar 24 at 9:58
    
I have two pages , first page contains delete button and second page contains add button. in second controller contains employees data and when ever click add button show popup with data – durga siva kishore mopuru Mar 24 at 10:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.