Angular modal not closing ($ uibModal)

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 cannot close the model when adding a user. In user-modal, I show a progress bar. The code works fine, but the error remains open. I also tried $ uibModalInstance, but the controller throws an error: unknown provider (unable to embed $ uibModalInstance on the same UserCtrl) I enter ui.bootstrap (ui-bootstrap-tpls-1.1.2.js)

Thank you for your time.

+5
source share
2 answers

Use modalInstance.close() inside your UserModalCtrl controller

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

I did something similar, I think.

I have a $modal controller that looks like this:

 angular.module('myApp').controller('infoCtrl', function ($scope, $uibModalInstance, loading) { $scope.editable = loading; $scope.$watch('editable.status', function(newValue, oldValue) { if (newValue == 'success'){ // close modal $uibModalInstance.close('ok'); } else if (newValue == 'error') { // show error message } }); }); 

Introduced loading is a service that looks like

 myApp.factory('loading', function() { return { status: '' } }); 

And when I change the status of my boot service to "success" (nowhere, not a modal controller), the modal closes.

I don’t know if this was exactly what you asked for, but I hope this helps too, just ask if something is clear!

EDIT: let's say you have a service with the value isCompleted: false , enter this service in your modal controller and use the $watch function, then when this isCompleted is changed to true , you close the modal.

0
source

Source: https://habr.com/ru/post/1242201/


All Articles