I am editing a record from a list, clicking on it opens this record in a modal with user information to edit, so far so good.
My drawback is that inside the modal I am loading a service that depends on the selected user, I execute this function in the OnInit
modal but since the modal loads in my main component when I open the modal that service is empty since it was executed when loading the component main and not when loading the modal.
How could I make my function run when I open the modal and not when the component loads?
Note: the modal is in a component and my list of records in another component
Main Template:
<app-modal modalId="editUser" modalSize="modal-lg" modalTitle="Editar Usuario - {{user.userId}}" modalIcon="ion-ios-person-outline">
<app-edit-user [user]="user"></app-edit-user>
</app-modal>
Main component (from here I call my modal):
onRowSelect(event) {
this.newUser = false;
this.user = this.cloneUser(event.data);
$("#editUser").modal();
}
Component Modal
getParameters(user){
console.log(user);
this._userService.getParameter(user).subscribe(
response => {
this.userParameter = response.pagedResult.resultado;
console.log(this.userParameter);
},
error => {
console.log(<any>error);
}
);
}
// Desde aqui llamo la función pero como se ejecuta al cargar el componente los datos siempre vienen vacios
ngOnInit() {
console.log(this.user.userId);
this.getParameters(this.user.userId);
}