I got the json data from the backend, and I want to save the data in a variable so I can fill out a table with them. Here is my code:
@Component({
selector: 'app-kontakte',
templateUrl: './kontakte.component.html',
styleUrls: ['./kontakte.component.scss'],
})
export class KontakteComponent implements OnInit {
textArea: string;
minlength: number;
maxlength = 100000;
constructor(private kontakteService: KontakteService) {
this.textArea = '';
this.minlength = 1;
}
ngOnInit(): void {
this.reload();
}
public reload():void {
this.kontakteService.getTpoContacts().subscribe((res) => {
this.textArea = JSON.stringify(res);
console.log(this.textArea); // <-- here I get the data as output
});
console.log(this.textArea) // <- here I get a blank string
}
}
I wanted to save the json data inside the textArea variable. Then use the data to fill out a tabe. Inside the subscription I get the data which is correct, but outside of it the this.textArea is blank.
Any suggestion how I could solve this? I'm very new to angular.