Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANGULAR 7 reload component view

Tags:

angular

I want to reload a component view by clicking button icon, without refreshing the whole page.

My view code:

<nb-card>
  <nb-card-header>
    <div class="row" style="font-size: 2.125rem !important;">
      <div class="col-sm-8">
        Tableau des Casiers 
      </div>
      <div class="col-sm-4 d-flex justify-content-end">
        <nb-action icon="ion-refresh sizeicone" (click)="refresh()"></nb-action>
      </div>
    </div>
  </nb-card-header>

  <nb-card-body>
    <ng2-smart-table [settings]="settings" (custom)="onCustom($event)" [source]="source"
      (deleteConfirm)="onDeleteConfirm($event)" (editConfirm)="onSaveConfirm($event)"
      (createConfirm)="onCreateConfirm($event)">
    </ng2-smart-table>
  </nb-card-body>
</nb-card>
like image 644
Soukaina Benchekroun Avatar asked Apr 02 '19 19:04

Soukaina Benchekroun


People also ask

How do you refresh a component from another component in angular 6?

To refresh, or better to say update another component from a different component, we can use the concept of Observables and Subject (which is a kind of Observable). This concept has an added benefit when data are to be received from APIs for CRUD operations.

How do you reload a component react?

React gives us two options in which we can reload a component. Either we can reload a component using the Vanilla JavaScript , or we can use the state to reload the component whenever a change is made in the state of that component.


1 Answers

In angular you don't need to refresh a component - angular will refresh page content automatically when it detects that variables, used on template, changes. So in refresh() method just update variables values. However if you really want to do it manually then you can use following construction:

template:

<my-component *ngIf="showComponent"></my-component>

ts file:

public refresh() {
   this.showComponent=false;
   setTimeout(x=>this.showComponent=true);
}
like image 139
Kamil Kiełczewski Avatar answered Oct 07 '22 13:10

Kamil Kiełczewski