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 - Angular Tutorial
From the course: Angular: Testing and Debugging
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
-
-
-
-
-
Adding a local storage service4m 38s
-
Fixing dependency injection errors3m 38s
-
Getting and setting data in local storage3m 18s
-
Adding a custom Angular pipe4m 51s
-
Using regular expressions to find content4m 13s
-
Using a pipe to change HTML content4m 17s
-
Common pipe errors1m 53s
-
Understanding Angular decorators2m 6s
-
Challenge: Filter the array of users by locationId30s
-
Solution: Filter the array of users by locationId1m 23s
-
-
-
-
-
-