Change CSS of PC on button click in CC?
To start with this blog post, let me put the focus on some of the terminologies that I have used in the title of it. So, the agenda is to change the CSS of our Parent Component with the help of a button inside our child component.
For those who are totally new to Angular, CSS stands for Cascading Style Sheets which help developers to style their Angular Applications. With the release of Angular 7, when we create a new Angular application using CLI, it asks us which style sheet format would we like to add to our application. See in the image below:
Proceeding after choosing the convenient stylesheet format, CSS for the sake of this blog post, we will create two components inside our application.
To create a component using CLI, we use:
ng g c component-name
To start with, create a button inside the template of a component.
Now to access this button to change the CSS on the parent component, we use @Output() and EventEmitter. To do that,
Now, let us go to other components to use this button and change the CSS.
And the Parent Component looks like this.
If we look at the CSS file now, it is kept very simple for understanding this article.
Having done this, let us look at the results now: