poniedziałek, 14 maja 2018

How to compare entity id and route param in angular.

Get param from url:


1
2
3
    this.subscription = this.route.params.subscribe((params) => {
      this.deskId = params['id'];
    });

Compare it with some other id like:


1
this.desks[i].id


1
2
3
4
5
if (this.desks[i].id === this.deskId) {
 console.log('true');
} else {
console.log('false');
}

- suprisingly got false.


Cast param to number:

1
this.deskId*1


then


1
2
3
4
5
if (this.desks[i].id === (this.deskId*1)) {
 console.log('true');
} else {
console.log('false');
}

got true.

Brak komentarzy:

Prześlij komentarz