Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Display only those results whose id matches the URL param

I have a URL parameter gatewayId and I want to display only those objects whose id matches the parameter.

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-message-receiver',
  templateUrl: './message-receiver.component.html',
  styleUrls: ['./message-receiver.component.scss']
})
export class MessageReceiverComponent implements OnInit {
  data: {
    message: string,
    gatewayId: number
  }[] =
  [
    {message: "Message 1", gatewayId: 1},
    {message: "Message 2", gatewayId: 2},
    {message: "Message 3", gatewayId: 3},
    {message: "Message 4", gatewayId: 1},
    {message: "Message 5", gatewayId: 2},
    {message: "Message 6", gatewayId: 3}
  ]
<div>
    <div>
        <button mat-raised-button (click)="goToGateway()">
            <span>&#8592;</span>
        </button>
        <button mat-raised-button (click)="sendMessage()" style="float: right;">Send message</button>
    </div>
    <ng-container *ngFor="let member of data">    
        <div>
            <ul>
                <li *ngIf="member.gatewayId === 1">{{member.message}}</li>
            </ul>
        </div>
    </ng-container>
</div>

(Here the filter is hardcoded so don't pay attention to that).

So if the URL is */1, I want to display only messages 1 and 4. I tried to do it with ActivatedRoute and ngFor/ngIf but can't get it done unfortunately.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In you component.ts:


gatewayId:number;

constructor(private route: ActivatedRoute) { }

ngOnInit() {
if(this.route.snapshot.params['id'])
      this.gatewayId = this.route.snapshot.params['id'];
}

In your component.html:

<div>
    <div>
        <button mat-raised-button (click)="goToGateway()">
            <span>&#8592;</span>
        </button>
        <button mat-raised-button (click)="sendMessage()" style="float: right;">Send message</button>
    </div>
    <ng-container *ngFor="let member of data">    
       
        <li *ngIf="member.gatewayId === gatewayId">{{member.message}}</li>
            
    </ng-container>
</div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!