0

When page load first time at that time I am displaying grid view with current user details.

Now in that I have added one checkbox.

So when user click on that checkbox then that grid should updated with all users list. Again if user uncheck that checbox so only see current user details.

Below is my code for that

**So I have two questions :

  1. Is this correct way what I am following ?
  2. What argument I need to pass when I call function from ngAfterViewInit**
<mat-checkbox (change)="showAllUsers($event)">
      Show All
    </mat-checkbox>

 showAllUsers(event:MatCheckboxChange){
    if(event.checked){
      this.getUsers();
    } else {
      this.getUsersById();
    }
  }

Now I am trying to call this function from ngAfterViewInit..

ngAfterViewInit(){
    this.showAllCompanies($event.);
  }

**So I have two questions :

  1. Is this correct way what I am following ?
  2. What argument I need to pass when I call function from ngAfterViewInit**
Test
  • 29
  • 5

1 Answers1

0

First you should not use ngAfterViewInit like that.

For your problem :


<mat-checkbox (change)="showAllUsers($event)">
      Show All
</mat-checkbox>


// you can do something like that if you dont want to pass throught an $event. 

defaultDisplay:boolean = false;

showAllUsers(){

    this.defaultDisplay = !this.defaultDisplay;

    if(this.defaultDisplay){
      this.getUsers();
    } else {
      this.getUsersById();
    }
  }

Option 3 :


<mat-checkbox (change)="showAllUsers(defaultDisplay)">
      Show All
</mat-checkbox>

defaultDisplay:boolean = false;
 
showAllUsers(defaultDisplay:boolean){

    this.defaultDisplay = !this.defaultDisplay;

    if(this.defaultDisplay){
      this.getUsers();
    } else {
      this.getUsersById();
    }
  }

Hope it will help you :)

  • This is not working for me.. Problem is that I need to just relaod grid not whole page.. so without ngafterviewinit how can I do that – Test Jan 16 '23 at 08:07
  • By loading new data you reload the whole page ??? maybe take a look : https://stackoverflow.com/questions/45300563/how-to-refresh-data-from-view-without-refreshing-the-whole-page-angular – Julien BEAUDOUX Jan 16 '23 at 08:16
  • I don't want to reload whole page.. just grid view of that page.. – Test Jan 16 '23 at 08:18