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**

1 Answer 1

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 :)

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

3 Comments

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
By loading new data you reload the whole page ??? maybe take a look : stackoverflow.com/questions/45300563/…
I don't want to reload whole page.. just grid view of that page..

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.