In this video, learn how to use the service class created in a previous video within components.
- Let's see how we can use the media item service … from within a component. … In the media-item-list.component.ts file, … we want to create the import statement for the service. … Then we need to create a constructor function … so we can have Angular do constructor injection. … We give that a private parameter named media item service … and set the type to media item service. … Then we can make use of the OnInIt life cycle event … by importing OnInIt from Angular core. … And declaring that the class implements OnInIt. … Then we can add an ngOnInIt method … and set the media items property of the component class … equal to a call to this.mediaitemservice.get. … And now we can delete the sample data from here. … This component class has the on media item delete function … so we can fill out the body of that with a call to … this.mediaitemservice.delete and pass it … in the media item it receives. … Finally, we can head over … to the media-item-form.component.ts file. … Then import the service at the top. …
- What is Angular?
- Working with components
- Binding events and properties
- Getting data to components
- Using directives and pipes
- Creating Angular forms
- Validating form data
- How Angular does dependency injection
- Making HTTP calls
- Styling components
Skill Level Intermediate
Angular: Building an Interfacewith Ray Villalobos2h 20m Intermediate
1. Architecture Overview
3. Directives and Pipes
5. Dependency Injection and Services
8. Styling Components
Next steps1m 20s
- 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.