0

I have a list with a lot of equipments. Each equipment has a button called "Detalhes". If I click in this button, I want to show just the info about that specific equipment (passing serialnumber, for example). How can I pass the serial number after switch between component?

Here's my html for the first page:

<div *ngFor="let equipment of equipments" class="card small card-small">
    <p>{{ equipment.equipmentName }}</p>
    <div class="container">
      <div class="card-content">
        {{ equipment.serialnumber }}
        <p>
          <a href="/equipDetail">Detalhes</a>
        </p>
        <p>
          <a (click)="open(modalcontent, equipment)">Editar</a>
        </p>
      </div>
    </div>
  </div>

/equipDetail is the component that I want to show, after user click. This component should have all the data about the equipment, I can get this data with http calls if I get the serialnumber first.

1 Answer 1

2

I assume you use angular routing, so you can just define router parameter like (let's suppose that your details component is called DetailsComponent):

Router config

....
{ path: 'equipDetail/:serialNum', component: DetailsComponent }
....

You can set redirection parameter in html using <a> like:

Link

....
<a [routerLink]="['/equipDetail', equipment.serialnumber]">Detalhes</a>
....

And you can read it in DetailsComponent like:

Parameter usage

....
constructor(private route: ActivatedRoute) {}
....
ngOnInit() {
   this.sub = this.route.params.subscribe(params => {
       const serialNum = params['serialNum'];
       // here you can use var serialNum to make a request to fetch data
   });
}

Hope that helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! Works like a charm.
Sure. I'm glad that it helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.