In my angular app. I am navigating from secondComponent to firstComponent and transferring the data using Router. I am able to do it successfully. After routing to the firstComponent, i want to implement some logic. I do not have any click events to implement the logic. As the firstComponent i am routing to is already initialized and rendered. Which type of method or a life cycle event can i use to implement the logic. I have tried to put the logic in constructor but it throws me an error as the method is implemented before navigating to the component ans the variable is not intialized.
FirstComponent
constructor(private route: Router,
private router: ActivatedRoute) {
this.router.params.subscribe(data => {
this.Search(data);
});
Search(data) {
this.source.addFilter({field: 'test', search: data.testValue});
}
}
SecondCompoennt
ngAfterViewInit() {
this.searchService.onSearchSubmit()
.subscribe((data: any) => {
const testValue = data.term;
this.route.navigate(['/test/path', {testValue}]);
});
}