I am trying to get the query parameter from the URL in to a component and it works as expected and now I want to get the data from this component in to another. But I am getting undefined
.
Component where I am trying to get the query parameter:
export class ProjectShipmentComponent implements OnInit {
public repProjectNumber : string;
constructor( private activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.activatedRoute.params.subscribe(params => {
this.repProjectNumber = params['reportProject'];
console.log(this.repProjectNumber);
})}
getPrjNum()
{
return this.repProjectNumber;
}}
Now I am trying to retrieve this repProjectNumber
in to another component like below
import { ProjectShipmentComponent } from '../project-shipment.component';
export class ReportingFilterComponent implements OnInit {
repPrj : string;
constructor(private psc :ProjectShipmentComponent ) {
this.repPrj = this.psc.getPrjNum();
console.log(this.repPrj);
I get undefined here. Is there any order in which the ngOnInit
is executed? Because while debugging I didn't see ngOnInit
executed when the getPrjNum
function call is made from ReportingFilterComponent
. How can I get this working?