Describe the bug
I'm using a modal dialog via the data-modal-toggle attribute, which only works fine when opening the project on the specific route that contains those modals. But when navigating to another route, it does not open again. I have to either reload the page or stop the Angular Cli and re-run it again.
To Reproduce
Steps to reproduce the behavior:
Create an Angular App with router outlet
Add a subpage/route that contains the modal component
create a table with several inserts that contain a button (In this case the modal component)
create a separated component for the modal, which will be called on every row of the table with a different ID every time.
asign IDs throw an @input variable to the component.
Open that page specifically
Verify all the modals work and on the Inspector of the browser verify both the Div with the modal, every attribute Data-modal-toggle and so have the specifical ID so IDs are Unique.
Navigate to another route
Navigate back to the page that has the table with the modal buttons
try to open any of the modals.
Expected behavior
Buttons should work, having navigated outside the component, each and every time you navigate back without having to reload the page or rerun the angular CLI
Desktop (please complete the following information):
OS: Windows 10
Browser Chrome
Version 123.0.6312.106
Additional context
While loading the page and inspecting it, every ID is unique. Modals only work when you havent navigated to another route, and if you do, you have to reload more than once. Specifically 2 or 3 times. First time it wont work.
I do have a router subscription on my App.component.ts file and I do have implemented the Tailwind config file and Angular.json file according to the guide provided by flowbite.
Here's the source code of the components that have the problem, the table component, the modal component with its respective TS files. Theres a Delete button that also does not work, but i have the same implementation of the Edit component, so once both should work... right?
I can paste a link to my repo if needed
users.component.html
<div class="p-4 border-2 border-gray-200 bg-white rounded">
<h2 class="mb-10 text-3xl font-extrabold leading-none tracking-tight text-gray-900 md:text-4xl">Team management</h2>
<p-tabView [(activeIndex)]="activeIndex">
<p-tabPanel header="All Users">
<div class="m-4">
<user-edit (userInfo)="handleEdition($event, false)"></user-edit>
</div>
<p-table *ngIf="users" [value]="users" [paginator]="true" [rows]="5" [showCurrentPageReport]="true" [tableStyle]="{ 'min-width': '50rem' }" currentPageReportTemplate="Showing {first} to {last} of {totalRecords} entries" [rowsPerPageOptions]="[5, 10, 20]">
<ng-template pTemplate="header">
<tr>
<th >Name</th>
<th>Email</th>
<th >Date Joined</th>
<th >Role</th>
<th >Actions</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-user>
<tr>
<td>{{ user.fullname }}</td>
<td>{{ user.email }}</td>
<td>{{ user.createdAt }}</td>
<td>{{ user.role }}</td>
<td>
<user-delete [user]="user" (deleteUser)="handleDeletion($event)"></user-delete> <user-edit [userToEdit]="user" [editMode]="true" (userInfo)="handleEdition($event, true)"></user-edit>
</td>
</tr>
</ng-template>
<ng-template pTemplate="paginatorleft">
<p-button type="button" icon="pi pi-plus" styleClass="p-button-text"></p-button>
</ng-template>
<ng-template pTemplate="paginatorright">
<p-button type="button" icon="pi pi-cloud" styleClass="p-button-text"></p-button>
</ng-template>
</p-table>
</p-tabPanel>
<p-tabPanel header="History">
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim
ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni
dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam
eius modi.
</p>
</p-tabPanel>
</p-tabView>
</div>
users.component.ts
import { Component, OnDestroy, OnInit } from '@angular/core';
import { UserService } from './users.service';
import { Subscription } from 'rxjs';
import { User } from './user.model';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrl: './users.component.scss'
})
export class UsersComponent implements OnInit, OnDestroy {
userSubscription: Subscription;
activeIndex = 0;
//this is just for demo purposes, i will refactor later for an actual model and an acual usage, not this...
users: User[];
constructor(private userService: UserService) {}
ngOnInit(): void {
this.userService.getUsers();
this.userSubscription = this.userService.usersChange.subscribe(users => this.users = users);
}
ngOnDestroy(): void {
this.userSubscription.unsubscribe();
}
handleDeletion(user: any){
this.userService.deleteUser(user);
}
handleEdition(user: User, edition: boolean) {
if(edition) {
this.userService.updateUser(user);
} else {
this.userService.createUser(user)
.subscribe(
data => {
console.log(data.description)
this.users.push(user);
this.userService.usersChange.next(this.users)
}
)
}
}
}
Describe the bug I'm using a modal dialog via the data-modal-toggle attribute, which only works fine when opening the project on the specific route that contains those modals. But when navigating to another route, it does not open again. I have to either reload the page or stop the Angular Cli and re-run it again.
To Reproduce Steps to reproduce the behavior:
Expected behavior Buttons should work, having navigated outside the component, each and every time you navigate back without having to reload the page or rerun the angular CLI
Desktop (please complete the following information):
Additional context While loading the page and inspecting it, every ID is unique. Modals only work when you havent navigated to another route, and if you do, you have to reload more than once. Specifically 2 or 3 times. First time it wont work.
I do have a router subscription on my App.component.ts file and I do have implemented the Tailwind config file and Angular.json file according to the guide provided by flowbite.
Here's the source code of the components that have the problem, the table component, the modal component with its respective TS files. Theres a Delete button that also does not work, but i have the same implementation of the Edit component, so once both should work... right?
I can paste a link to my repo if needed
users.component.html
users.component.ts
edit.component.html
edit.component.ts