I am encountering an issue with a function in my service, represented by the following code:
@Injectable()
export class MyService {
constructor(private http: Http, private router: Router) {}
getInfo() {
return this.http.get(url).map((response: Response) => {return JSON.parse(response)}
}
}
This method is being invoked from ngOnInit
of a component as shown below:
export class MyComponent implements OnInit {
constructor(private service: MyService) { }
ngOnInit() {
this.service.getInfo().subscribe((data) => {
this.info = data;
});
}
}
The problem arises when navigating to this component directly through the browser URL it works fine. However, when using the router.navigate
method to navigate to this component, an exception is thrown,
getInfo is not a function
Could someone please guide me on identifying the root cause of this issue and help rectify what I might be doing incorrectly?