0

I am using angular bootstrap UI for modal pop up. My requirement is that when user clicks on "delete" link,first modal pop should open and when user click ok then delete rest API is called which is used to delete record. But for that I need to pass record id to my delete function. So how can I pass record id to modal insta controller as I am calling this function when user click ok button on modal pop up. Here is my code.

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

  $scope.open = function (size,billingID) {
  console.log("in model instance" + billingID);
  var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: ModalInstanceCtrl,
      size: size,
       resolve: {
        items: function () {
          return $scope.items;
        }
      }
    });

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



};


  var ModalInstanceCtrl = function ($scope, $modalInstance, items) {


      $scope.items = items;
      $scope.selected = {
        item: $scope.items[0]
      };
      $scope.billingID=billingID;
      $scope.ok = function ( billingID) {

        $modalInstance.close($scope.selected.item);
        deleteCC(billingID);

      };

      $scope.cancel = function () {
          console.log("in model instance cancel");
        $modalInstance.dismiss('cancel');
      };
    };

`

I am able to obtain my billing id in open()But how can I access same building id in my ModalInstanceCtrl ?

2 Answers 2

2

Add it to resolve object while creating modal instance

var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: ModalInstanceCtrl,
  size: size,
   resolve: {
    items: function () {
      return $scope.items;
    },
    billingID: function () {
      return billingID
    }
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

did you mean from angular controller you want to call a service so answer is here,

var app = angular.module('app', []);

app.controller('appController', ['$scope', 'appService' function($scope, appService)
{   
    $scope.message = appService;

}]).
factory('appService', function()
{
    retutn function()
    {
        'from service message Hi!! ';   
    }
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.