Currently, I am working on an Angular project (version 16) and my goal is to create a dialog modal that includes a checkbox for "do not show again".
Here is the process I envision:
- When a user visits the web application for the first time, a dialog modal will appear with the "do not show again" checkbox
- The user will read the content of the modal and choose to check the checkbox
- If the user returns to the web app shortly after, the dialog modal will not appear again because the browser will remember the user's choice to "do not show again"
I have heard about the LocalStorage functionality but I am unsure about how to implement it in Angular.
Here is the code I have so far :
TS :
openDialog() {
const dialogRef = this.dialog.open(ModalDialogComponent);
dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`);
});
}
HTML (Angular-Material UI) :
<h2 mat-dialog-title>My dialog modal</h2>
<mat-dialog-content class="mat-typography">
<mat-tab-group>
<mat-tab label="First">First</mat-tab>
<mat-tab label="Second">Second</mat-tab>
</mat-tab-group>
<mat-checkbox class="example-margin">Do not show again</mat-checkbox>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button>
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>Install</button>
</mat-dialog-actions>
If you have any suggestions or solutions to implement this feature, I would greatly appreciate it. Thank you.
EDIT :
Here is a Stackblitz demo to showcase what I am trying to achieve.