Find out how to write custom services for your Angular 2 application to make updating data in your URL much easier as your application grows.
- [Narrator] Let's add code to our custom service…so we can set data in the u-r-l.…In our u-r-l service we'll create a new,…generic set method that accepts two arguments.…The first argument will be the type…of data we want to set.…I'll call this argument Type.…The second argument will be the value we're setting.…I'll call this argument Value.…Our Type argument will always be a string.…So I'll set its type as string.…
And our value can be a string or an object.…So I'll set its type as any.…The navigate method we'll use returns a promise.…Responding true if the u-r-l update was successful…and false if the u-r-l update failed.…We'll set the return type of our set method…to a promise with a generic type as boolean.…If you're using visual studio code,…you may see an error message after…setting the return type of our set method.…
Don't worry, this error is just telling us…that the method isn't returning anything yet…and will go away as soon as we finish…writing the rest of the code.…To keep things simple and easy to understand,…
- 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.