I just started learning Angular and it seems a bit different to React which was the first JS framework/library I learned.
I watched some courses this week and I thought I should write down some code and see how far it gets me, test what I've learned. You might recognize the app as it's been one of the challenges listed on Frontend Mentor and I've completed this in React so I wanted to give it a go in Angular aswell.
This is what I've done so far. https://i.sstatic.net/Lp1Qj.png
Atm, I am not fetching data from the API because I don't know how, just yet. However, what I want to do is:
- when I click the Light button, the theme should switch to Dark and vice-versa. I created a service for this.
export class ThemeService {
isLightTheme:boolean = true;
changeTheme():void {
this.isLightTheme = !this.isLightTheme;
}
}
What I did was to link up the button in the header to the changeTheme() function
TS
changeTheme():void {
this.themeService.changeTheme();
this.isLightTheme = this.themeService.isLightTheme;
}
HTML
<button (click)="changeTheme()">...</button>
But I am not sure how to listen to changes of this isLightTheme property in the service and apply it to other components that need to know which theme to apply.
- How can I create the functionality that when there's something typed in the search input, the country cards get filtered? Also a service? How am I supposed to link up two different components (search input is a component, the cards container is a different input)? Observables?