question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow custom config to be passed into the modal template ref for use in components

See original GitHub issue

Currently 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:open
  • Created 7 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
PEsteves8commented, Nov 7, 2016

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.

1reaction
dneuercommented, Dec 21, 2016

const modalRef = this.modalService.open(MyComponetWithContentForModal); modalRefComponentInstance.customProp1 = modalContext.prop1;

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found