-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Instantiate controller when opening modal #728
Comments
Yeah, this is something I'm trying to do as well. You can use I eventually factored it out into a service that wraps the |
👍 I'd like to have this feature here as well. I'm only using angular-ui $modal now because they support this separated controller for modals. @evillemez can you share your solution? |
@rodrigoreis22 Sure thing. I put the implementation in a gist, please excuse the CoffeeScript if that's not your thing. :) https://gist.github.com/evillemez/ef89eb7be58de098d6a0 In our app, we have various modals that can be triggered from multiple places within the app. So, we have a provider for defining what the modal is, along with default configuration for AngularStrap's |
Thanks @evillemez |
Not sure if there is any progress on this, but I have decorated |
In case you do not use lodash/underscore.js (you should consider), I have created a gist for it too: |
+1 |
1 similar comment
+1 |
As long as more and more people migrating from bootstrap-ui this feature can come up really handy. |
+1 @pswai great job! I've extended your gist adding some features. |
+1 this is very important feature as it encourages better separation of concerns, also resolve allow easy way of passing data into modal controller. |
+1 I am shocked that this isn't possible. Logic in modals can be very complex, so they need a seperate controller. Having all your modal logic in your main controller, is very bad. Controllers and resolve are both available in Angular-UI. This makes modal architecture in Angular-UI better. |
+1. I understand how to have a separate scope for the modal, but the only way I know to assign a dedicated controller for the modal is by @pswai's solution looks interesting (thanks for posting this). It would be nice to only rely on standard functionality in the library, however. |
I think the proper way to do this would be to use a global compiler helper that would support a broad range of options. Something like Angular Material's compiler.js. I'm more than open to PR's providing this feature. |
Unfortunately I think I'm too inexperienced with Angular / JS to provide PRs for the library itself, but I thought I'd share something that just worked for me in case anyone finds it useful in the meantime. My scenario is that I use a service to open a modal. The purpose of the service is to provide a promise-like interface (taken from a Plunker that @mgcrea provided) as well as creating the custom scope. A dedicated .html template is used with the modal. It is necessary to use one of two possible controllers, chosen based on parameter(s) passed when opening the modal. Controller declaration in my html template is:
The service:
With the above solution, with the service injected into a controller, either I realise there is lots of duplication in the service code -- I will probably edit this a few times as I refine it. |
Take a look at this project. This is a similiar behavior like in UI-bootstrap. You control controllers, input, what happens before modal, after, etc. Much more control. |
Finally took the time to backport the |
Thanks @mgcrea that's fantastic. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature request - be able to pass in a Controller when programmatically creating modals. This is a nice way to pass in data to the modal that angular-ui also allows.
Example:
Another benefit of this over the current approach is that it allows instantiating the Controller when the modal is created rather than at page load.
If angularstrap already supports this but I've missed it somewhere please let me know, otherwise I'm happy to have a crack at implementing if you think it's a good idea.
The text was updated successfully, but these errors were encountered: