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

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