I have two components which have the same child but with different inputs.
In the child in the ogOnInit I initiate the inputs in my model. When I click on one of the components for the first time the child's html is updated but when I click again I still have the inputs of the last component saved in the dom.
which is normal because the component is loaded in the dom only once and the ngOnInit is only executed once.
So, my need is to find a solution to update the data in the child with every click.
Here is my code :
First Component :
import { Component } from '@angular/core';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {}
<app-explore-container amount="1000000" delayed="0" rate="5" duration="180" name="Crédit Immobilier"></app-explore-container>
2nd Component :
@Component({
selector: 'app-tab2',
templateUrl: 'tab2.page.html',
styleUrls: ['tab2.page.scss']
})
export class Tab2Page {}
<app-explore-container amount="200000" delayed="0" rate="6.0" duration="60" name="Crédit Consommation"></app-explore-container>
Child Component :
@Component({
selector: 'app-explore-container',
templateUrl: './explore-container.component.html',
styleUrls: ['./explore-container.component.scss']
})
export class ExploreContainerComponent implements OnInit, OnChanges {
@Input() name: string;
@Input() amount: number;
@Input() rate: number;
@Input() duration: number;
@Input() delayed: number;
constructor(public simulation: Simulateur) { }
ngOnInit() {
this.simulation.amount = this.amount;
this.simulation.rate = this.rate;
this.simulation.duration = this.duration;
this.simulation.delayed = this.delayed;
}