I have a problem in my angular application that Button Status can not be changed in a child componnent, now I show my code firstly.
this is a child component
<child-component
[(canAddMore)]="canAddMoreSo"
[index]="index"
[formGroup]="form"
[selectedValues]="soValues"
controlName="so"
></child-component>
and child component ts file
@Input() selectedValues: number[];
@Input() index: number;
@Input() formGroup: FormGroup;
@Input() controlName: string;
private _canAddMore: boolean;
@Input() public set canAddMore(value: boolean){
this._canAddMore = value;
this.canAddMoreChange.emit(value);
}
@Output() public canAddMoreChange: EventEmitter<boolean> = new EventEmitter<boolean>();
constructor() { }
public add(): void{
this.canAddMore = false;
}
public remove(): void{
this.canAddMore = true;
this.formGroup.get(this.controlName).reset();
}
this child component, there are 2 buttons, the one is add button, which can show select dropdown, and the other one is delete, which can hidden select dropdown.
the HTML of this child component looks like this:
<label [formGroup]="formGroup">
<select class="parameterInputSelect" [formControlName]="controlName" *ngIf="!_canAddMore">
<option *ngFor="let param of selectedValues" [value]="param">{{param}}</option>
</select>
<button mat-mini-fab color="primary" matTooltip="Add Sort Order" *ngIf="_canAddMore"
(click)="add()">
<mat-icon>add</mat-icon>
</button>
<button
class="delete-button"
mat-mini-fab color="primary"
matTooltip="Remove Sort Order"
(click)="remove()"
*ngIf="!_canAddMore">
<mat-icon>delete</mat-icon>
</button>
</label>
the problem is, if I click add button, and the delete button, the select dropdowm will not be hidden.
any solutions?