angular modal not closing ($uibModal )

Scorpio picture Scorpio · Feb 3, 2016 · Viewed 24k times · Source
angular
.module('angProj')
.controller('UserCtrl',
    ['$scope', '$uibModal',
        function ($scope, $uibModal) {

            $scope.results = function (content, completed) {
                var modalInstance = $uibModal.open({
                        backdrop: 'static',
                        keyboard: false,
                        animation: $scope.animationsEnabled,
                        templateUrl: '/Scripts/angularApp/views/user-modal.html',
                        controller: 'UserModalCtrl',
                        resolve: {
                            items: function () {
                                return $scope.items;
                            }
                        }
                    });

                if (!completed || content.length === 0) {
                    return;
                }

        modalInstance.close();
        modalInstance.dismiss('cancel');

I am not able to close the model on user add completion.. On user-modal i am showing progress bar.. the code runs fine without error but the modal remains open. I also tried $uibModalInstance but the controller throws error: unknown provider (not able to inject $uibModalInstance on the same UserCtrl) I am injecting ui.bootstrap (ui-bootstrap-tpls-1.1.2.js)

Thanks for your time.

Answer

Rock picture Rock · Feb 3, 2016

Use modalInstance.close() inside your UserModalCtrl controller

app.controller('UserModalCtrl', ['$scope', '$modalInstance' function($scope ,modalInstance {
  $scope.close = function () {
   modalInstance.close();
  };
}]);