1

I have a google map on my project, I have made control position for the button like this:

map: any;
mapReady(event: any) {
  this.map = event;
  this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(document.getElementById('open'));
  this.map.controls[google.maps.ControlPosition.TOP_CENTER].push(document.getElementById('Settings'));
}

I have buttons like this:

<button mat-mini-fab class="shadow bg-light" style="margin-top: 10px !important;" [hidden]="hideOpen" id="open"
    (click)="openbtn()" *ngIf="open_btn">
    <mat-icon>menu</mat-icon>
</button>

<button mat-mini-fab class="shadow bg-info" style="margin-top: 10px !important; margin-left: 30px;"
    [hidden]="hideSettings" id="Settings" *ngIf="!open_btn">
    <mat-icon class="text-white">4k</mat-icon>
</button>

Initially, the first button will be visible, second is hidden, when I click on the first button I should display the second button.

I have tried this:

open_btn: boolean = true;
close_btn: boolean = false;
openbtn(){
  this.open_btn = false;
  this.close_btn = true;
}
3
  • 1
    Either use *ngIf or [hidden] attribute. If you're using both, then both need to adjusted to show the element. So in the event handler you also need to include hideSettings = false. Commented Jul 30, 2020 at 12:01
  • @MichaelD I have tried by removing the [hidden] on the both buttons, but it didn't worked. Commented Jul 30, 2020 at 12:09
  • 1
    If you remove the [hidden] then it should work - stackblitz.com/edit/… Commented Jul 30, 2020 at 12:14

1 Answer 1

1

As already @yash told, If you remove the [hidden] property it works just fine.

https://stackblitz.com/edit/ng-if-buttons-erufv9

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.