I'm trying to get data from external API. This is my Typescript function:
export class BarChartcomponent implements OnInit{
  public chart: any;
  data: any = [];
  
  constructor(private service:PostService) { }
  ngOnInit(): void {
    this.service.getPosts().subscribe(response => {
     this.data = response;
    });
    
    this.createChart();
  };
}
I want to use "data" variable for further data manipulations, but when I try to use it outside the subscribe function it result "undefined". I know that is a scope error but I don't know how to fix it.
 
     
     
    