2 способа, которые я могу придумать, в зависимости от вашего кода: просто установите глобальную переменную и укажите ее в своей подписке:
`
data = null; //here
const id = this.route.snapshot.paramMap.get('id');
this.dataService.GetFormById(+id).subscribe(response => {
console.log(response);
const temp = response['TemplateJson'];
this.data = temp; //here use it wherever you want using this.data, but check if its null
})
initJq();
var formData = Data
this.formBuilder = (<any>jQuery('.build-wrap')).formBuilder({ formData });
// Sample code to handle promise to get for data on page load directly
this.formBuilder.promise.then(formBuilder => {
console.log(formBuilder.formData);
});
}`
Или (так как большая часть кода, который требует данных из подписки, должна выполнятьсяasync) просто используйте канал rxjs и передайте данные методу или любому другому оператору, которого вы хотите:
this.dataService.GetFormById(+id).pipe(
map(response => {
console.log(response);
const temp = response['TemplateJson'];
const data = temp;
return data
}),
tap((data)=>{ // can be anyother operator and the map above can also be removed
//do something
})).subscribe();