Ways to conceal a button according to a particular trigger

On the page labeled standing-orders-details, I have configured it so that the display of the New Order button is hidden, but only if I first visit the new-order page.

  1. To begin, I need to ensure that the New Order button remains hidden on the standing-orders-details page.

In my TypeScript file, I declared a variable like this:

isNewOrderVisited: boolean = false;

Next, here's the method implementation:

    goToNewOrder(): void {
        this.isNewOrderVisited = true;
        this.router.navigate(['/orders/newOrder']);
      }

The HTML template contains the button code as follows:

    <button *ngIf="isNewOrderVisited" (click)="goToNewOrder()" class="btn btn-primary m-1" type="button">New Order</button>

Now, as expected, when I am on the standing-orders-details page, the New Order button stays hidden!

  1. However, there is an issue! After creating an order from the new-order page, upon redirection to the standing-orders-details page, I should now see the New Order button!

I'm unsure how to tackle this challenge?

I believe the problem lies within this portion of the code:

    newOrderRequest(tokens: SignatureOtpModel | undefined): void {
        if (tokens) {
          this.service.createNewOrder(this.order!, tokens).pipe(
            takeUntil(this.unsubscribe$)
          ).subscribe(res => {
            if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
              this.router.navigate(['/orders/standingOrdersDetails']);
            } else {
              this.router.navigate(['/orders/error/' + ConfirmOrderTypeEnum.Add + '/' + JSON.stringify(res.RETURNLIST)]);
            }
          });
        }
      }

I've shared all my code with you for context.

standing-orders-details.component.ts

    // Code snippet for StandingOrdersDetailsComponent
// Includes declarations and methods for handling standing orders

    

new-order.component.ts

    // Code snippet for NewOrderComponent
// Contains functionalities related to new order creation and details fetching
    

Answer №1

If you want to pass a parameter through the URL, you can do so like this.

Update in app-routing.module.ts:

{ path: 'standingOrderDetails', component: StandingOrdersDetailsComponent, data: {isNewOrderVisited: false}},  

In your StandingOrdersDetailsComponent.ts, you can access the parameter as shown below:

isNewOrderVisited: boolean = false;

constructor(
    private route: ActivatedRoute,
  ) { }


ngOnInit(): void {
    this.route.queryParams.subscribe(params => {
      this.isNewOrderVisited = params['isNewOrderVisited']
    });
}

Examples of how to use the URL with the parameter:

http://localhost:4200/orders/standingOrderDetails?isNewOrderVisited=false
http://localhost:4200/orders/standingOrderDetails?isNewOrderVisited=true

EDIT:

newOrderRequest(tokens: SignatureOtpModel | undefined): void {
        if (tokens) {
          this.service.createNewOrder(this.order!, tokens).pipe(
            takeUntil(this.unsubscribe$)
          ).subscribe(res => {
            if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
              this.router.navigate(['/orders/standingOrdersDetails?isNewOrderVisited=false']);
            } else {
              this.router.navigate(['/orders/error/' + ConfirmOrderTypeEnum.Add + '/' + JSON.stringify(res.RETURNLIST)]);
            }
          });
        }
      }

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

Issues encountered when attempting to refresh page with react-router-dom

I successfully implemented a private route system in my React application using react-router-dom. However, I encountered an issue where upon reloading a page, it briefly redirects to /login before properly displaying the page. How can I resolve this unexpe ...

Automatically Formatting Currency in Angular 6 with Keyup

I am currently facing an issue with using the keyup event in an input element that has a currency pipe in my Angular 8 application. <input placeholder="€0.00" (keyup)="onKey(pointIndex, $event.target.value, item.quantity)" value="{{item.unitPriceWith ...

Angular problem: Cannot connect to 'formGroup' as it is not a recognized property of 'form'

Struggling to set up a simple form in Angular consisting of a label and an input field. Despite following suggestions to import FormsModule and ReactiveFormsModule, I'm still encountering errors as mentioned numerous times on StackOverflow. Here&apos ...

The button fails to appear when navigating

Hello everyone, I have a code snippet for a functional back button in my Angular application, but I'm facing an issue with adding it to an existing constructor. I already have a constructor for navigating between pages, but it seems the back button co ...

Generate a unique Object URL for the video source by utilizing the binary string obtained from the backend

I've been facing an issue with loading binary video data from my backend using fastAPI. When I curl the endpoint and save the file, it plays perfectly fine on my laptop. For the frontend, I'm using React+Typescript. I fetch the binary video data ...

I'm puzzled as to why my get request seems to be hit-or-miss, working at times but returning a 404 not found error at other

Currently in the process of learning Angular and working on a project that involves a MongoDB database and Express for APIs. I am trying to retrieve comments for a specific post using the post ID. The GET request should return a list of comments, but the ...

Something went wrong with geolocation: ERROR TypeError: Unable to assign value to property 'lat' of null

Issue with Retrieving User's Location In my Angular project, I am trying to access the user's current location and store the longitude and latitude values in two properties named lng and lat. However, I am facing a persistent issue where I keep ...

Determining the quantity of variations within a union in Typescript

Is it possible to determine the number of types in a union type in Typescript, prior to runtime? Consider the following scenario: type unionOfThree = 'a' | 'b' | 'c'; const numberOfTypes = NumberOfTypes<unionOfThree>; c ...

What is the best way to test the validity of a form while also verifying email availability?

I am currently working on implementing async validation in reactive forms. My goal is to disable the submit button whenever a new input is provided. However, I am facing an issue where if duplicate emails are entered, the form remains valid for a brief per ...

Unable to execute Mikro-ORM migrations on a bun

In my current project, I am using TypeScript with Bun + Elysia. Previously, I migrated my app from a NestJs project that was working fine with MikroORM. However, after switching to `bun`, the migrator command doesn't work as expected: bunx --bun mikro ...

Challenges faced when using an array of objects interface in Typescript

I have initialized an array named state in my component's componentDidMount lifecycle hook as shown below: state{ array:[{a:0,b:0},{a:1,b:1},{a:2,b:2}] } However, whenever I try to access it, I encounter the following error message: Prop ...

Unable to locate the module '@vitejs/plugin-react' or its associated type

After creating the project with npm create vite@latest and selecting ts-react, everything seemed to work fine when I ran npm run dev. However, in my vs code editor, I encountered the error message "Cannot find module '@vitejs/plugin-react' or its ...

Should we rethink using nested *ngFor loops in Angular 7?

Currently, I am dealing with an object that consists of an array. This array has the capability to contain one or multiple objects similar to the parent object. The levels of nesting in this structure could potentially be infinite. To showcase all the data ...

How do I increase a date by a specific number of days in Ionic 3?

ionViewDidEnter() { let self = this; self.originationsProvider.getOrigination() .then((data) => { self.origination = data; console.log(self.origination, "slefOrigination"); this.complete = self.origination.filter(( ...

How can I use ngx-editor to insert an HTML block at the current cursor position by clicking a button?

I am currently using ngx-editor within Angular 7. My goal is to insert HTML at the cursor's position upon clicking on parameters from a list. The current view displays how the parameter is appended when clicked, as shown in the image attached https:// ...

Typescript: Implementing the 'types' property in a function returned from React.forwardRef

I'm exploring the option of adding extra properties to the return type of React's forwardRef function. Specifically, I want to include the types property. Although my current implementation is functional, given my limited experience with TypeScri ...

Do not generate authentication code in JHipster using the --skip-server flag

Is there a reason why the authentication part is lost when generating a project with '--skip-server'? yo jhipster --skip-server It seems that upon generating the project without the server, the authentication gets affected (on AJS/A2). Is thi ...

Examples or links pertaining to the tabs bar in Ionic

Is there a specialized tutorial or example available for finding non-default tabs in Ionic 5? I'm looking for alternatives to the default tabs and would appreciate any help in the form of links, examples, or tutorials. Thanks in advance! https://i.ss ...

Efficiently incorporating multiple properties into one in Angular

Within my Angular service, I have defined variables in the following manner: export class MyService { someVariableA = 1; someParams = { someVariableB, otherVariable: this.someVariableA }; } In a component, I update 'someVariableA&a ...

unable to locate the nested routes in the folder for remix

Hey there, I've been using the remix to create a basic page and I'm trying to organize the routes using folders. Here is my project directory: - app/ - root.tsx - examples/ - route.tsx - child1/ - account.tsx In the examples di ...