0

My Parent page looks like this.

html:

<counter  [conversationId]="conversationId"></counter>

component:

public conversationId: string;

public showModal() {   
 this.conversationId = '1234'
 this.modalService.showComponent(CounterPage, { class: 'modal-lg' }); 
}

My Child page looks like this.

 @Input() conversationId: any;
 public ngOnInit  (): void {
    alert(this.conversationId); //shows undefinded.
  }

Looks like this is common issue here. None of the solutions worked for me.

Chatra
  • 2,989
  • 7
  • 40
  • 73
  • What is `conversationId` when it is being passed in? If you are passing in `undefined` then it would make sense that it remains `undefined`. – Ashley May 20 '19 at 22:36
  • I am not passing undefined. My code clearly shows assigning '1234' to conversationId before calling show component – Chatra May 21 '19 at 02:15

1 Answers1

0

The params receive values before the method ngAfterContentInit().

See the lifecycle of angular in this image: https://v2.angular.io/resources/images/devguide/lifecycle-hooks/hooks-in-sequence.png

try:

@Input() conversationId: any;
 public ngAfterContentInit  (): void {
    alert(this.conversationId); //shows undefinded.
  }