Unlock the power of Angular Router to execute unique actions with each click

Exclude the route from the button actions:

<div *ngFor="let data of allData" routerLink="/view-detail">
 <div>
   <p>{{data.content}}</p>
</div>
<button>SaveData</button>
<button>ApplyData</button>
</div>

When I click on a button, only the action specific to that button should be performed without navigating to a new page. However, clicking on the div triggers the route, and clicking on the buttons triggers both the route and the button action.

Is there a way to perform a button click action without triggering the route, even when the buttons are nested inside the routerLink?

Answer №1

<input type="submit" value="Save" onclick="saveData(event)">

...

saveData(event) {
  event.preventDefault();
  // ...
}

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

What is the best way to reassign key-value pairs in JSON mapping using JavaScript/TypeScript?

Given {"a": {"name": "king", "firstname": "Thomas"},"b": {"age": "21"}} I'm exploring a simple way to convert it to {"name": "king","firstname": "Thomas","age": "21"} In the realm of Javascript/Angular. Any helpful suggestions are greatly appreci ...

Alternative for using useRouteMatch to retrieve parameters

I'm currently refactoring this code and struggling to find a suitable replacement for this section. This is due to the react-router-dom v6 no longer having the useRouteMatch feature, which I relied on to extract parameters from the URL: import React, ...

Calculating the total sum of an array utilizing filter and reduce techniques

How can I calculate the total value of all my products in the list by adding numbers together? this.totalValue = this.items.filter((item) => item.qtyvalue) .map((item) => item.qtyvalue) .reduce ...

What is the benefit of utilizing ngSubmit over just using a basic button and function?

Lately, I've been pondering whether to utilize ngSubmit or simply bind a (click)="submit()" on a button. There's been much debate about using submit and ngSubmit, but is it necessary to rely on the traditional HTML submit method? Particularly wh ...

What is the best way to change `props.children` into a JSX element?

When using React functional components, we have the ability to render children in the following way: import React from 'react'; const MyComponent = (props: React.PropsWithChildren) => { return props.children; } However, I encountered an ...

Pagination problem arises when sorting through items

I am facing an issue with filtering items on different pages of my React website. The problem I encounter is that the filtering functionality only works on the initial page where the data is loaded. Code: CustomersEpolicyPage.tsx import React, {useEffect ...

rxjs5 - the WebSocket constructor is missing

I can't seem to figure out this basic task. I'm attempting to create an Observable from rxjx/observable/dom/webSocket in RxJS5, but I'm not using typescript, or es6 modules... just plain 'ole good commonJS. Despite following the documen ...

What steps can be taken to effectively build a test suite architecture using Jest?

After exploring all the available resources on the Jest documentation website, including various guides and examples, I have yet to find a solution to my specific question. I am in search of a methodology that would enable me to individually run test case ...

Unable to update the value of the p-editor component in PrimeNG

After creating a form with the p-editor element for rich formatted text entry, a problem arose when attempting to update the form with server values using Angular's reactive form patchValue method. The editor does not update as expected with the new v ...

Angular Bounce Effect: Adding a Touch of Fun to Your

I'm utilizing the angular animation plugin ( https://www.npmjs.com/package/@angular/animations ) in my project. I am now looking to incorporate a bouncing effect when adding or removing items from an array. Below is the template snippet: <h2 *ngI ...

Implementing dynamic validation rules in Angular forms

In my code, there is a part where I need to make certain fields required. Initially, only the emailAddress field is required, but under a specific condition (res.isSuccess === true), I also need to set firstName, lastName, and companyName as required. The ...

Tips for preventing duplicate data fetching in Next.js version 13

I am currently in need of retrieving information from the database, generating metadata, and displaying the page content. The current method I am using is as follows: export const generateMetadata = async ({ params: { questionSlug }, }: Props): Promise&l ...

Angular 2 Issue: @Input() Directive Not Recognized - Unresolved Reference Error

I am a beginner trying to grasp Angular2 concepts from ng-book 2(v49). Below is the code snippet from article.componenets.ts file: import { Component, OnInit } from '@angular/core'; import { Article } from './article.model'; @Componen ...

Issue with FullCalendar-vue and Typescript: the property 'getApi' is not recognized

Struggling to integrate FullCalendar-vue with Typescript, I encountered a problem when trying to access its API. This is how my calendar is set up: <FullCalendar ref="fullCalendar" :options="calendarOptions" style="width: 100%& ...

Showcasing regional JSON information on an Angular 9 template

I want to showcase the following JSON data in my HTML template [ { "Event Name": "Get All Information", "Info": "Retrieves all data stored in the system. Caution: this request returns more than 8MB and takes over 5 seconds", "Endpoint": "/ ...

What is the best way to utilize "exports" in package.json for TypeScript and nested submodules?

Looking to leverage the relatively new "exports" functionality in Node.js/package.json for the following setup: "exports": { ".": "./dist/index.js", "./foo": "./dist/path/to/foo.js" } so that ...

I am currently unable to retrieve any results for my fullcalendar tooltip

I am currently working on setting tooltips for events using Primeng's fullcalendar. Despite initializing the tooltip in the web console, I am unable to see it when hovering over an event. My development environment includes Typescript, Primeng 7.0.5, ...

What distinction can be drawn between binding to an attribute and binding to a property in Angular?

When we bind to data attributes, we typically use the syntax [attr.data-something]="expression". However, is it necessary to bind to properties like id, title, name in the same manner? Wouldn't binding to a property (without attr.) produce t ...

What is the best way to uninstall yarn from angular cli so that I can switch to using npm for installing packages?

When attempting to install packages using yarn for tooling, an error occurred stating: 'yarn' is not recognized as an internal or external command, operable program or batch file. Package installation failed with the details provided above. For f ...

Creating custom components that encapsulate the functionality of Angular Material tabs component

I am aiming to incorporate the Angular Material tabs component within my shared components. Here is the component I'm attempting to wrap: Note: Each tab can display a component: <mat-tab-group> <mat-tab label="First"> Content ...