ModalDialogParams - allow ability to be tokenized, provide differently or remove
See original GitHub issueIn an attempt to integrate modal handling seamlessly across web + {N} shared codebase, ModalDialogParams
presents a problem in the way it is currently designed.
Instead of:
const modalParams = new ModalDialogParams(options.context, closeCallback);
const providers = ReflectiveInjector.resolve([
{ provide: Page, useValue: page },
{ provide: ModalDialogParams, useValue: modalParams }, // let's remove this
]);
Perhaps the params could be simply lifted off the ModalDialogService
itself and do away with ModalDialogParams
altogether to do something like this:
constructor(private modal: ModalDialogService) {}
public close() {
let optionalArgs: any = {
anyData: 'test'
};
this.modal.close(optionalArgs);
}
Could look something like:
@Injectable()
export class ModalDialogService {
public static closeCallback: Function;
public context: any;
private containerRef: ViewContainerRef;
// etc.
public close(args) {
this.context = undefined; // clear any previously passed context
ModalDialogService.closeCallback(...args);
}
public showModal(type: Type<any>, options: ModalDialogOptions): Promise<any> {
let viewContainerRef = options.viewContainerRef || this.containerRef;
if (!viewContainerRef) {
throw new Error("No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
}
const parentPage: Page = viewContainerRef.injector.get(Page);
const resolver: ComponentFactoryResolver = viewContainerRef.injector.get(ComponentFactoryResolver);
const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY);
this.context = options.context; // allow shown components to access context
return new Promise((resolve, reject) => {
setTimeout(() => ModalDialogService.showDialog(type, options, resolve, viewContainerRef, resolver, parentPage, pageFactory), 10);
});
}
private static showDialog(
type: Type<any>,
options: ModalDialogOptions,
doneCallback,
containerRef: ViewContainerRef,
resolver: ComponentFactoryResolver,
parentPage: Page,
pageFactory: PageFactory): void {
const page = pageFactory({ isModal: true, componentType: type });
let detachedLoaderRef: ComponentRef<DetachedLoader>;
ModalDialogService.closeCallback = (...args) => {
doneCallback.apply(undefined, args);
page.closeModal();
detachedLoaderRef.destroy();
};
// etc.
Simplifying setup by only needing to work with 1 service ModalDialogService
instead of 2. It would also make tokenized setups for code sharing between web + {N} more achievable.
If this makes sense, I can offer a PR for this soon.
/cc @vakrilov
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
The tokenization of real estate: An introduction to fractional ...
Ability to create liquidity. Real estate tokens are easily and securely transferable by way of blockchain technology, allowing investors to ...
Read more >Tokenization in NLP: Types, Challenges, Examples, Tools
It's a crucial step for building an amazing NLP application. There are different ways to preprocess text: stop word removal,; tokenization,; stemming.
Read more >Overview | Device Tokenization Developer Site
To enable Google Pay device tokenization support for your cards, ... The ability to delete or uninstall the Google Wallet app depends on ......
Read more >The tokenization of assets is disrupting the financial industry
be about to fundamentally change with the arrival of tokenization. ... ICOs, which can produce different tokens ... tokenization provides for both investors....
Read more >Chapter 2 Tokenization
2.1 What is a token? In R, text is typically represented with the character data type, similar to strings in other languages. Let's...
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 Free
Top 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
Hi @vakrilov,
Thank you for your response. I’ve just managed to make this work using another approach. I’ ve created two files (services) ‘dialog-params.service.tns.ts’ and ‘dialog-params.service.ts’:
Then, with a gulp task, if I am building {N} app, I rename ‘dialog-params.service.tns.ts’ to ‘dialog-params.service.ts’.
In my custom dialog component I am importing it as follows:
Do you see any drawback in this approach?
For future reference, I made it working with something similar to @codeback solution. What I did was basically:
modalForm.service.tns.ts
modalForm.service.ts
I make sure to set a known ID to the dialog when opened with
MatDialog
, this step is important.ModalDialogParams
for the web version. So I have:modalForm.params.tns.ts
modalForm.params.ts
On {N} I export the already present
ModalDialogParams
, while on web I create a custom version, added to theproviders
list on my web module, which uses theMatDialog
service and the known ID to retrieve theMatDialogRef
and invoke close.modalForm.component.ts
Now when I invoke
closeCallback
the right chain of events is started and things are done as they should. I am using it in my repo https://github.com/bracco23/weight-stats-frontend/commit/a58287bd450a02afdf6e350efb081770c210042d