I have a component with a list of all users, and when we click on edit
or add new
I open same modal box with a form for edit or for add new user. In case I want to edit user I need to show user data in form in modal box. My modal box is in another component, and I need to pass data to modal.
In my user.component
I get data for selected user and I set it to
const modalRef = this.modalService.open(AddComponent);
this.userService.getUserDetail(username).subscribe((response: UserModel) => {
this.user = response;
modalRef.componentInstance.user = this.user;
});
And in modal box component
I set
export class AddComponent {
addNewUserForm: FormGroup;
@Input() user;
constructor (...){
console.log(this.user) //get undefined
}
}
I also try set console.log(this.user)
in ngOnInit
and ngAfterViewInit
but always get undefined
Thank you for help...