Find out how to write custom services for your Angular 2 application to make updating data in web storage much easier as your application grows.
- [Instructor] Let's add set and remove methods…to our custom browser storage service.…Our setSession method takes two arguments.…The key for the data…and the value we wish to assign to that key.…I'll call my arguments key and value.…The key will always be a string,…so we'll add the type annotation note of string…to the key argument.…The value can be of any type,…so we'll add a type annotation of any…to the value argument.…
Value using browser storage must always be stored as strings…so we'll convert the value argument to a string…using JSON.stringify and assign it to a new variable.…I'll call mine data…which will be assigned to JSON.stringify…and we'll parse the value from our setSession method…into the stringify method.…We then reference the window object…using the setItem method on the Session Storage property…to assign the key value pair.…
We'll type window.sessionStorage.setItem.…We'll parse in the key and the new data.…The setItem method does not return anything,…so I'm going to explicitly return an object…
- Overview of data storage options
- Saving and retrieving data from the browser
- Setting routes in the URL
- Using query strings and fragments instead of routes
- Saving and retrieving data from a server
- Working with user input
- Using JSONP instead of HTTP
- Why writing custom services is important
- Writing custom services for working with browsers and servers
Skill Level Intermediate
1. Getting Started
Application overview1m 39s
2. Data Storage Options
3. Storing Data in the Browser
4. Storing Data on a Server
5. Writing Custom Services
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.