From the course: Angular: Testing and Debugging
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Getting and setting data in local storage - Angular Tutorial
From the course: Angular: Testing and Debugging
Getting and setting data in local storage
- [Instructor] Let's use the new web storage service in our useless component. We imported the service earlier in this course and now we need to instantiate it in the constructor. I'll make a new line here and type a private web storage service with a lowercase w colon web storage service with an uppercase w. Next I'll change the update method to save the filter state to local storage. I'll make a new line here and type this dot web storage service dot set. I need to set the key here, this can be any string you like. I'm going to use the key of users, all upper case and the value is going to be this dot users. This wavy line here is the editor telling us there's an issue. I'm going to hover over to see what's going on. Looks like the set method expects a string here but we're passing in an array. There's a couple of ways we can transform this array into a string. I think the easiest here is to just use JSON stringify I'm going to highlight our property, cut type JSON stringify pass…
Contents
-
-
-
-
-
(Locked)
Adding a local storage service4m 38s
-
(Locked)
Fixing dependency injection errors3m 38s
-
(Locked)
Getting and setting data in local storage3m 18s
-
(Locked)
Adding a custom Angular pipe4m 51s
-
Using regular expressions to find content4m 13s
-
(Locked)
Using a pipe to change HTML content4m 17s
-
(Locked)
Common pipe errors1m 53s
-
Understanding Angular decorators2m 6s
-
(Locked)
Challenge: Filter the array of users by locationId30s
-
(Locked)
Solution: Filter the array of users by locationId1m 23s
-
(Locked)
-
-
-
-
-