The service remains operational while the button's status undergoes a change

In my data table, each row has a column containing buttons. To ensure that only the button in the clicked row is executed, I include the index of that row in the start/pause timer function.

I decided to create these functions in a service so that the timer would continue to run even when switching pages and not be destroyed.

The issue I'm facing is that when the timer is running and I change pages, the state of the buttons changes. For example, if I click play, it turns green, but when I return to the page, the button is no longer green. I suspect that the problem lies in losing the line index when changing pages, as the service is still active.

Does anyone have any suggestions on how to resolve this?

HTML

            <div class="row">
              <button type="button" data-toggle="dropdown" class="btn ClassPlay">                  
              </button>
              <div class="dropdown-menu">
                <a class="dropdown-item" *ngIf="currentState=='pause'" routerLinkActive="active"
                  (click)="currentState='start'; startTimer(data)">Start</a>
                <a class="dropdown-item" *ngIf="currentState=='start'" routerLinkActive="active"
                  (click)="currentState='pause'; pauseTimer(data)">Stop</a>
              </div>
            </div>

Answer №1

Example provided, make sure to view the link below.

Check out this link for more information

Summary of Actions Taken:

  1. Removed transform method from service and utilized date pipe to display time in 'HH:mm:ss' format

  2. Moved the currentRowIndex property into service

  3. Set the service as public for easy access in the template using taskService.method() or taskService.property

  4. Added clearInterval function to service.startTimer()

  5. Updated startTimer() and pauseTimer() methods in component.ts

  6. Note that *ngFor="let data of datas" should be replaced with *dxTemplate="let data of 'cellTemplate'" along with the corresponding images

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporate a vibrant red circle within a tab of the navigation bar

I'm looking to incorporate a red dot with a number into a messaging tab to indicate new messages. Below is the HTML code: <ul class="nav pw-nav pw-nav--horizontal"> <li class="nav-item"> <a class="nav ...

Angular 8 is throwing a NullInjectorError because it cannot find a provider for AngularFireAnalytics

After running 'npm test', I encountered the following error message: NullInjectorError: StaticInjectorError(DynamicTestModule)[ComparePageComponent -> AngularFireAnalytics]: StaticInjectorError(Platform: core)[ComparePageComponent - ...

Encountering a CORS error while utilizing a Node.js Express API with an Angular frontend

While developing an API using Node.js, Express, and MongoDB, I encountered a CORS error when trying to call the API from an Angular application. Strangely enough, the API works fine when deployed on Render, but throws an error locally. Error: Access to XM ...

What causes the left click to not trigger in Kendo's Angular Charts?

My homepage features a simple bar chart that displays correctly, but I am having trouble capturing the left click event (the right click works fine). This is an example of code from my template: <kendo-chart *ngIf="(dataExists | async)" [ ...

Sending data to back-end server using Multer, Node.js, and Express via a POST request

I have been facing an issue while trying to send a form from my local system to the backend server via a POST request. Every time, it seems to go with --binary-data instead of going with --form. Below is a sample curl command that I am looking to replicat ...

Tips for inserting a row component into a table using Angular 7

I am currently using the latest version of Angular (7.2.0). I have created a custom tr component as follows: import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-table-row', templateUrl: './table- ...

The Vercel error indicates that the file or directory '/var/task/node_modules/shiki/themes/one-dark-pro.json' does not exist

import { serialize } from 'next-mdx-remote/serialize'; import readingTime from 'reading-time'; import remarkGfm from 'remark-gfm'; import rehypeSlug from 'rehype-slug'; import rehypeAutolinkHeadings from 'rehype ...

What is the best way to design a circular icon using OpenLayers?

I am currently incorporating openlayers into my ionic app and working on placing users on the map. I have encountered a problem as I am unsure how to apply custom CSS styling to the user element, which is not directly present in the HTML. In the screenshot ...

An error has occurred in Typescript stating that there is no overload that matches the call for AnyStyledComponent since the update to nextjs

Upgraded to the latest version of nextjs, 13.3.1, and encountered an error in the IDE related to a styled component: Received error TS2769 after the upgrade: No overload matches this call. Overload 1 of 2, '(component: AnyStyledComponent): ThemedSty ...

Vitest surpasses Jest by providing explicit type declarations, ensuring no more "unknown type" errors

Transitioning from Jest to vitest has been a smooth process for me. I'm currently in the midst of converting the following code snippets: // Jest const myLib = jest.requireActual("mylib.js") to this: // Vitest const myLib = await vi.importA ...

Is it feasible to append an element to the result of a function that returns an array?

Is it possible to push something to an array returned by a function, but not directly? Instead, I want to push it back into the function itself. hierar() { return [{ h: 1 }, { h: 2, hh: [{ u: 2.1 }, { u: 2.2 }] }, { h: 3, hh: [{ u: 4 }, { U: 5 } ...

Infinite loop caused by Angular navigation within route guarding

The routes in my application are configured as shown below: {path: '', redirectTo: 'login', pathMatch: 'full'}, {path: 'todos', component: TodosComponent, canActivate: [AuthGuard]}, {path: 'add-todo', ...

Using TypeScript and NestJs: Spread types can only be generated from object types

I'm encountering an issue while trying to pass two parameters using the spread operator from the book.controller to the book.service.ts service. The error message I'm receiving is: Spread types may only be created from object types It's w ...

Exploring the canDeactivateFn syntax with Angular Documentation

As a first-year university student, I recently discovered that the canDeactivate() guard in Angular is deprecated, while the canDeactivateFn guard functions without any issues. Admittedly, navigating through official documentation is still new to me. From ...

Do Prisma Migrations Require a Default Value?

I'm struggling with Prisma data modeling and have tried almost everything to resolve an error I keep getting. The error states that the table needs a default value even though I have already assigned it an ID. I attempted to remove the relation name, ...

Connecting an Angular application to a URL hosted on localhost

I am currently working on an Angular project where one of the links needs to redirect to a different website. During development, this link points to a localhost URL like localhost:4210. However, due to security reasons in Angular, using such URLs is cons ...

Issue with Angular authentication during login attempt

I am a beginner in Angular and I'm using this method to allow users to log into the system. loginuser(){ const user = { username: this.username, password: this.password }; this.Auth.loginUser(user).subscribe((res)=>{ ...

Invoke a shared function within multiple component HTML files when an onchange event is triggered by a universal service

Hello there, I am currently working with angular 11. In my project, I have three components named C1, C2, and C3. These components do not have a parent-child relationship but they all share a common method called F1. Right now, F1 is declared in each compo ...

Find the variance between today's date and a selected date, then initiate the timer based on this variance

I have a grid containing data. I utilize the loadGrid() function to preload data or conditions before the grid finishes loading. When the active state is set to 1, my intention is to initiate a timer by calculating the difference between the current date ...

Retrieve the component's name using ReactElement.type.name

In my current project, I am working with React and Typescript. I need to retrieve the name of a functional component, which I have discovered can be accessed through the 'type' property of the component like this: component.type.name. Initially, ...