dwmkerr / dwmkerr/angular-modal-service

Close in a single controller?

Open
#281 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
618
Forks
312
Avg merge
3d 23h
Merged PRs (30d)
1

Description

When the user clicks a button on my modal I want to call a function which applies some logic and then closes the modal, I want to use a single controller:

```
function MyController($scope, $http, $window, AlertService, vcRecaptchaService, ModalService, close) {

$scope.agreeTerms = function() {
// some logic...
close(true, 500);
}

$scope.popModal = function(template, controller) {
ModalService.showModal({
templateUrl: template,
controller: controller,
preClose: (modal) => {modal.element.modal('hide');}
}).then(function(modal) {
modal.element.modal();
modal.close;
});
};

}
```

In my template:

`ng-click="popModal('termsConditions', 'MyController')"`

The button calls the agree terms funciton. At run time I get an error:

Unknown provider: closeProvider <- close <- MyController

I have seen other solutions and it requires using a separate modal controlleer, in my case I want to use one because the logic applied in my functon called by the button on the modal needs to be in the same scope as the original controller.

Is this possible?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the ModalService.showModal call in the issue and how the MyController dependency list is resolved. Trace the close dependency and the modal callback usage; done means determining whether one controller can provide the button logic and close the modal without the Unknown provider error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angularjs, javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.