1
I need guidance please, I have a component structure in an Angular design:
1) Head component
2) Body component and within it the Rodape component
The button inside the Header component needs to show/hide the <div>
which are within the other components, in the case of <div class="card"></div>
and the <div class="footer></div>
.
Example:
Cabecalho.html component:
<button (click)="toggleShow()">Esconder / Exibir</button>
Component Cabecalho.ts:
isShown: boolean = false;
toggleShow() {
this.isShown = ! this.isShown;
}
Component Body.html:
<div class="card" *ngIf="isShown">
<p>Conteúdo</p>
</div>
And within the Body Component the Rodape Component:
<div class='footer' *ngIf="isShown">
<p>©</p>
</div>
Can you help me?
We don’t know how the hierarchy of your folders is in the project, but depending on how it is used eventEmitter() ,or, the most suitable one would be a service.
– LeAndrade
I tried to use the eventEmitter(), but I’m new to Angular, I couldn’t understand how to apply it yet. Could you help me? The folder structure and as I described above: header, body and inside Rodape body. Thank you.
– Munir Baarini
The cable component is not the parent of the other components so Mitter will not work will have to do this using a service.
– LeAndrade
Yes, the header is not the father, he is brother of the body component, the rodape component is child of the body component, the best solution would be a service? can help me?
– Munir Baarini
So I’m tight here on the trampo hj but gives a search on behaviorSubject, this link is very good and in Portuguese you can understand cool, if you follow the steps there you will probably be able to do what you want: https://medium.com/xp-inc/sharedata
– LeAndrade
Thank you Leandrade
– Munir Baarini
You got it right there, Munir?
– LeAndrade
Opa Leandrade, okay? Actually not yet, I was trying to use the @input developer, you can give me a strength using this feature?
– Munir Baarini
With @Input it won’t work because they are sibling components and not each other’s child other than body and footer, but because you couldn’t use service? That link passes td you need!
– LeAndrade