When I select a link on the current page, I would like the information in the input fields to be cleared

Currently using Angular 8, I recently included onSameUrlNavigation: 'reload' to my router. This change has successfully allowed the page to reload upon a second click on the same link. However, I've noticed that the input fields on the reloaded page are not being cleared. Why is this happening and what steps can I take to address it?

Answer №1

When using onSameUrlNavigation: 'reload', the router will be re-executed but the currently active component will remain in its current state. If you need a workaround, you can listen to router events within the component and take action once the navigation is complete:

ngOnInit(): void {
    this.router.events.pipe(
      // wait for navigation to end
      filter((event: RouterEvent) => event instanceof NavigationEnd)
    ).subscribe(() => {
      // programmatically clear input fields
    });
  }

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

A step-by-step guide on effectively adopting the strategy design pattern

Seeking guidance on the implementation of the strategy design pattern to ensure correctness. Consider a scenario where the class FormBuilder employs strategies from the following list in order to construct the form: SimpleFormStrategy ExtendedFormStrate ...

Is it worth incorporating dependency injection for injecting classes?

In the AngularJS days, factory was commonly used to inject classes instead of instances. This practice continues in Angular 2: {provide: MyClass, useFactory: () => { return MyClass }} ... constructor(MyClass) { let instance = new MyClass(); } Howe ...

Using leaflet-markercluster in Angular 2 with Leaflet

Having some trouble trying to configure leaflet with the leaflet-markercluster plugin using angular 2. Although I've managed to make it work with angularJS in the past, I'm facing issues in angular and could use some guidance on what might be cau ...

Why do my messages from BehaviorSubject get duplicated every time a new message is received?

Currently, I am using BehaviorSubject to receive data and also utilizing websockets, although the websocket functionality is not relevant at this moment. The main issue I am facing is why I keep receiving duplicated messages from BehaviorSubject. When exa ...

Guide to incorporating ThreeJS Collada loader with TypeScript / Angular CLI

I currently have three plugins installed: node_modules/three My Collada loader was also successfully installed in: node_modules/three-collada-loader It seems that the typings already include definitions for the Collada loader as well: node_modules/@ty ...

TypeScript perplexed Babel with its unfamiliar syntax and could not compile it

Encountered a problem while attempting to compile typescript. It appears that babel was unable to comprehend the "?." syntax on the line node.current?.contains(event.target) export function useOnClickOutside(node: any, handler: any) { const handlerRef = ...

The selector of the Angular component class may lose its original casing

Having trouble with a Components selector and need some guidance. I attempted to assign the class .Home_root like this: @Component({ selector: '.Home_root', templateUrl: './home.component.html', styleUrls: ['./home.component ...

What is the process for transferring files from a NodeJS website to Azure CDN?

I am searching for a solution to upload images directly to Azure CDN. Here is the situation: My client Portal built with Angular (4.x) enables users to manage their website, and they need the capability to upload images that will be displayed on the sit ...

Saving a JSON object to multiple JSON objects in TypeScript - The ultimate guide

Currently, I am receiving a JSON object named formDoc containing data from the backend. { "components": [ { "label": "Textfield1", "type": "textfield", "key": "textfield1", ...

Unable to retrieve base64 pdf file due to network connectivity problem

I am trying to download a base64 pdf file from local storage using vue3 typescript. Here is the code snippet I'm using: downloadPDF() { const linkSource = `data:application/pdf;base64,${'json.base64'}`; const downloadLink = ...

Obtaining Data from an Array with Reactive Forms in Angular 4

Just starting out with Angular 4 and trying to figure out how to populate input fields with information based on the selection made in a dropdown. <select formControlName="selectCar" class="form-field"> <option value="">Choose a car&l ...

You cannot use the "this" keyword outside of a class body

I am facing an issue with my function, can someone help me? Here is the code: function remove_multi_leg(): void { if (Number($("#search_no_legs").val()) < 2) { return; } const removeId: number = Number($(this).attr("data-number")); const ...

Angular 8 - How to Intercept and Customize HTTP Error Responses

I am looking for a way to intercept and edit an HttpResponse that is of type HttpErrorResponse, specifically with a status code of 500. I want to change the status to 200 and populate its body so that I can treat it as a successful HTTP call in the subsc ...

An error occurred during runtime while attempting to resolve all parameters for the UserService

I recently started using Ionic and I am trying to set up a sidebar with a user profile header, displaying the user's details as seen in other similar apps depending on who is logged in. Unfortunately, I have come across the following error: Runtime ...

Angular 4 with Typescript allows for the quick and easy deletion of multiple selected rows

I am currently working on an application where I need to create a function that will delete the selected checkboxes from an array. I have managed to log the number of checkboxes that are selected, but I am struggling to retrieve the index numbers of these ...

Angular validation with input binding using if statement

I have developed a reusable component for input fields where I included a Boolean variable called "IsValid" in my typescript file to handle validation messages. Here is the code from my typescript file: export class InputControlsComponent implements OnIn ...

Tips on leveraging separate files for classes in TypeScript

I'm currently working on developing a TypeScript application where each class is saved in its own .ts file. I prefer to use VS Code for this project. So far, my compile task seems to be functioning correctly (transpiling .ts files into .js files). How ...

Utilizing Ngrx store for Reacting form validation with the integration of asynchronous validation

I'm currently working on an Angular 8 project where I aim to showcase form errors through NgRx store while utilizing reactive forms with a custom asynchronous validator. login.component.ts @Component({ selector: 'auth-login', templateU ...

When the button onClick event is not functioning as expected in NextJS with TypeScript

After creating a login page with a button to sign in and hit an API, I encountered an issue where clicking the button does not trigger any action. I have checked the console log and no errors or responses are showing up. Could there be a mistake in my code ...

Errors have been encountered in the Angular app when attempting to add FormControl based on the data retrieved from the backend

This specific page is a part of my Angular application. Within the ngOnInit method, I make two API calls to retrieve necessary data and iterate through it using forEach method to construct a reactive form. However, I am facing one of two different errors ...