From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Solution: Filter the array of users by locationId

Solution: Filter the array of users by locationId - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Solution: Filter the array of users by locationId

(upbeat music) - [Instructor] Okay, here's my solution for the challenge. Keep in mind that my solution and your solution may be different and that's okay. I made a new pipe called location ID using the same NG generate command we've used in previous videos. The transform method takes in an array of users or null as well as any number of optional location IDs. If the array is null or there's no IDs passed in, just return the value. Otherwise I filter the array using JavaScript's array dot filter method. For each user in the array I compare that user's location ID against all the IDs passed into the pipe. I use JavaScript's array dot some method to do this. Some returns a Boolean used by the filter method. If true, it adds that user to the new array. If false, it does nothing. Finally, I return a new filter to array of users. Let me show you the HTML template. Here's where I send the user's array into my new pipe and here's where I pass in the location IDs. I use colons to separate…

Contents