Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does angular "$uibModalInstance.close(data)" work?

The official documentation of AngularJS does not contain anything that describes how $uibModalInstance.close works, in the following code fragment, scope.close is a method used to close the modal window and pass an object to the caller controller

var app = angular.module('myApp');

app.controller('ModalController', ['$uibModalInstance', modalControllerFn]);

function modalControllerFn($uibModalInstance) {
    var scope = this;
    
    // some data object
    scope.data = {key1: "value1", key2: "value2"};
    
    scope.close = function() {
        $uibModalInstance.close(scope.data);
    }
}

Question (1)

Does passing anything belonging to the modal scope using `$uibModalInstance.close` (non-literal value, i.e: `scope.x`) prevent angular garbage collection from destroying the entire modal scope? Is this a scenario for causing memory leaks?

Question (2)

How does angular `$uibModalInstance.close(data)` exactly work?
like image 509
Abdo Adel Avatar asked Jan 07 '16 10:01

Abdo Adel


1 Answers

Please have a look at the JavaScript example on Angular UI Bootstrap's website here: Angular UI Bootstrap Modal

Scroll down just a bit and click the JavaScript tab to see the code.

The important part is this:

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

Above, the selectedItem variable is what is passed into:

$uibModalInstance.close(rightHereGetsPassedAsResult)
like image 75
agenaille Avatar answered Sep 17 '22 17:09

agenaille