-2
I have a Dashboard:
<app-navbar></app-navbar>
<div style="display: flex; height: 90vh;">
<app-sidebar id="sidebar" class="hide"></app-sidebar>
<app-funil></app-funil>
</div>
and within that Dashboard, I call my sidebar (which is also a component), and the app-funnel component'.
So far so good, but inside the funnel, I have a button, which has the effect of making the sidebar appear and disappear, and I need to access this button that is inside the funnel through the Dashboard TS, but I’m not getting it.
This is my Dashboard TS, with the function to make the sidebar appear and disappear:
handleShowSidebar() {
document.getElementById('showSidebar').addEventListener("click", function() {
document.getElementById('sidebar').classList.toggle('hide')
})
}
ngOnInit() {
this.handleShowSidebar();
}
Dear Arthur in Angular and similar It would be better to control the classes by ngClass, instead of redoing what exists ready, even the click event would be better controlled on the own (click)= that already exists in the structure of Angular.... it seems to me that your intention to control via pure JS is perhaps by inexeriencia with Angular, which makes this a problem of XY PS: the downvote is not mine.
– Guilherme Nascimento
I don’t see why use ngClass, because they’re not the same components: In this case, I have 3 (Dashboard, Funnel and Sidebar), I need to pick up INSIDE the funnel, click the button, and make INSIDE the Dashboard, it makes the Sidebar component disappear...
– Arthur Felipe
Dear Arthur ngClass, click, ngFor, ngIf work with your HTML, it doesn’t need to be a component, as I said, I think that in fact you still don’t quite understand the Angular and so this reinventing the wheel for a feature that already exists in the angular.
– Guilherme Nascimento
Yes dear, but it needs to be a component, because this 'funnel' will be replaced by another component, once you click on the sidebar, so the solution cannot come from HTML...
– Arthur Felipe
blz, I tried to explain, I’ll try to say otherwise, you’re trying to do something that you can do directly in Angular, will trigger the same event, what you have to learn is how ngClass works with variables and even Ifs within the angular syntax itself or the object of the class belonging to the specific "template". Believe me, you can do all this without having to do the event and selection of elements.
– Guilherme Nascimento
Arthur gives a search on @Input and @Output that make the communication between components in the Angular the first vc passes values of the parent component(Dashboard) pro filho(funnel) and the second emits values of the child pro pai.
– LeAndrade