Module 8 - Dependency and Services Flashcards
Module 8 - Dependency and Services
Import
//In the .ts file
import { CardbuttonsService } from ‘../cardbuttons.service’;
Module 8 - Dependency and Services
Configure
//In .ts file
constructor(private cardService: CardbuttonsService) {}
Module 8 - Dependency and Services
Use
//In the .ts file
like() {
this.cardService.likeCard();
}
//In the HTML file
(click)=”like(‘likebutton01’)”
Code the command that will create a new Angular service called yourloginnameQuizService
ng generate service yourloginnameQuizService
What is the purpose of the @Injectable() decorator in Angular?
The @Injectable() decorator is used to mark a class as a service that can be injected into other components or services, allowing dependency injection
How do you inject a service into a component in Angular? Provide an example from the slides.
A service is injected by including it in the component’s constructor.
Example:
constructor(private cardService: CardbuttonsService) { }