Allow custom config to be passed into the modal template ref for use in components
See original GitHub issueCurrently it is possible to be reusing the same template over again across multiple components for modals. It would be good to support passing in a config object into the modal context used for binding reusable properties.
For example, I would like to be able to do this
<template #myModalTemplate let-c="close" let-d="dismiss" let-config="modalContext">
<my-component [customProp1]="config.prop1" [customProp2]="config.prop2" (close)="c($event)" (dismiss)="d($event)"
</template>
in order to extract my common template & config into a reusable component.
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (12 by maintainers)
Top Results From Across the Web
angular - How to pass parameteres to modal? - Stack Overflow
Here's how you can pass data to your HTML Template in Angular2 import {Component} from '@angular/core'; import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; ...
Read more >Allow custom config to be passed into the modal template ref for use ...
Currently it is possible to be reusing the same template over again across multiple components for modals. It would be good to support...
Read more >How to pass data to and receive from NG Bootstrap modals
I have used Bootstrap in the past and was a huge fan of it. ... The hard part was to wire the Bootstrap...
Read more >How to create a reusable Modal component in Angular 9 ...
As you can see, there are many aspects of our modal we can take care of. The developer who's using this component can...
Read more >Modal - Angular powered Bootstrap
Content can be provided as a TemplateRef or a component type. If you pass a component type as content, then instances of those...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Personally, I would also like to have the options of passing in values when opening a modal from its template reference. For organization purposes sometimes I do prefer to have the <template> in the same place as the component that opens it, but at the same time I would prefer not to pollute the components properties with some values that are really only relevant for the modal when it opens. It’s not a big deal, though.
Another issue that I had and maybe this is due to the lack of proper design or knowledge of the library, I was going to open a modal using the ElementRef, but ended up making use of the component approach, by creating a component and passing it instead. The problem was that I wanted that component to use the same service instance as the component that triggers the opening of the modal, but I got the error ‘no provider for the service’, so I had to add the service to the providers array of the modal component, which felt unnecessary, since it was already provided in the module to which the main component belonged to.
@pkozlowski-opensource isn’t that racy, though? What if the component can’t do anything useful without customProp1? I understand that ngOnInit is called after input properties are bound, but my assumption was that that only holds if angular creates the component through encountering it’s selector in markup. Am I misunderstanding? Is angular waiting around before calling ngOnInit even for components created from within event handlers, etc?