Reputation: 2662
I have language service that contains direction(ltr/rtl).
So when i open dialog, i specify the direction like this:
const dialogRef = this.dialog.open(SomeComponent,
{ direction: this.i18nService.dir}
);
Is there a way to set the direction for all dialogs according to the service?
Upvotes: 4
Views: 2321
Reputation: 7279
You can set globals when you include providers
@NgModule({
providers: [
{provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
]
})
but I don't think you can change it globally after that.
Anyway you can always wrap the call with your own service like this:
import { Injectable, Component } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { I18nService } from './path/to/i18nService.service.ts';
@Injectable()
export class MyDialogService {
constructor(private i18nService: I18nService, private dialog: MatDialog ) { }
open(component: Component, config = {}): MatDialogRef {
return this.dialog.open(component, Object.assign(config, { direction: this.i18nService.dir }));
}
}
Upvotes: 5