IdanCo / ng1bs4

AngularJS with Bootstrap 4
https://idanco.github.io/ng1bs4
38 stars 13 forks source link

Improve Component: Modal #29

Open langdonx opened 7 years ago

langdonx commented 7 years ago

Allow the modal service to accept a component, its bindings, and then allow that component to manage the modal and return data to the caller. It doesn't appear that you can do this currently.

langdonx commented 7 years ago

UI Bootstrap has support for this concept, but it doesn't do that great a job with it. It'd be nice to see modals with component support, more similar to how UI Router handles components. Meaning that a component doesn't have to be designed to work with UI Router... UI Router can reference any component and pass necessary bindings to it. UI Bootstrap, on the other hand, asks that components take a specific set of bindings:

{
    close: '&',
    dismiss: '&',
    modalInstance: '<,'
    resolve: '<',
}

...and call close or dismiss to resolve or reject the Promise. Fixing the mandatory resolve bit seems quite possible, but resolving the Promise might be more tricky. One way or another, the component has to be aware that it is being used inside of a modal if it wants to communicate with whatever code opened it. Perhaps an AngularJS Service can somehow bind the two together, rather than relying on a binding to inject info. I imagine they injected resolve instead of each individual binding simply to avoid naming collisions, but I'm not sure. If a Service isn't the solution, maybe a more uniquely named binding could do the trick and allow the component to not have to be a modal-only component.

IdanCo commented 7 years ago

I was banging my head on how to approach it, I think the component idea could be an excellent solution. And a service to make the component aware of the modal and communicate with the "parent" controller really sounds like the right approach.

I'll play around with it a little and come back with more thoughts...

nvivo commented 7 years ago

@IdanCo,

I use UI Bootstrap modal extensively to do complex screens. Component support is mandatory to keep this simple. Currently, UI Bootstrap supports components and allows me to do:

var instance = $uibModal.open({ component: someModalComponent });

What would it take to support it and do you need help implementing it?

IdanCo commented 7 years ago

@nvivo I totally agree and any help would be highly appreciated!

I admit I'm not sure how to approach this, so even a partial PR to help us get started will be welcomed...

jbeaudoin11 commented 7 years ago

I'm also interested into this !

nvivo commented 7 years ago

I have been thinking about this and wondering, and I know this may be too late, but why re-invent everything to support BS4 if most of the changes are in the HTML? Why not simply fork the current version and do the changes to the templates and properties? Wouldn't it be much easier than starting from scratch?