I have an Angular 4.x app with a http request that is getting sent and I am getting back valid json from the endpoint (I can see this in the initial console.log) - the problem is I cannot see this data outside on the ngOnInit() just below where I have the console.log
Can anyone suggest what the issue is?
export class SidebarComponent implements OnInit {
constructor(private http: HttpClient, private userService: UserService) { }
ngOnInit() {
this.http.get('https://dev.myapp.com/api/angularfour/auth',
{ params: new HttpParams()
.set('token', this.userService.getAuth().__token)
.set('apiversion', '1')
.set('appid', this.userService.getAuth().appid) })
.subscribe(data => {
console.log('data', data); // can see this data
});
}
console.log('menu data outside init', data); // cannot see this data?