0
Good evening person, I’m on a project where I wanted to add that button that hides and shows some information. But the tricky thing is that this button is in one component and the information to be hidden is in another. For example:
header.componente.html
<div>
<div class="btn-hidden btn-feature">
<img title="Ocultar" (click)="btnHide()">
</div>
</div>
header.componentts.
import { Component, OnInit, Output } from '@angular/core';
@Component({
selector: 'app-header-dashboard',
templateUrl: './header-dashboard.component.html',
styleUrls: ['./header-dashboard.component.sass']
})
export class HeaderDashboardComponent implements OnInit {
@Input() showValue;
constructor() { }
btnHide() {
console.log(this.showValue);
this.showValue = !this.showValue;
}
}
Here would be the component with the information to be hidden
Details.component.html
<div>
<p *ngIf="!showValue" class="card-account-amount">{{ value | currency: 'BRL' }}</p>
<p *ngIf="showValue" class="card-account-amount">R$ --</p>
</div>
Details.component.ts
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-account',
templateUrl: './account.component.html',
styleUrls: ['./account.component.sass']
})
export class AccountComponent implements OnInit {
@Input() showValue = true;
constructor() { }
ngOnInit(): void {
}
}
So it worked in a way, if I switch to showValue = false or showValue = true, change the values here:
<div>
<p *ngIf="!showValue" class="card-account-amount">{{ value | currency: 'BRL' }}</p>
<p *ngIf="showValue" class="card-account-amount">R$ --</p>
</div>
But it does not change the values by clicking on the button of the Header component, which I am locked in. Only if I change the.ts file of Accountcomponent
That’s right, to pass data from parent component to son you use Input() and from son to father you use Output() with eventEmitter().
– LeAndrade
can give me an example with the code above?
– Nickolas Moreira
I edited the question to be clearer
– Nickolas Moreira