Я вызываю этот метод testDataService
, который определен в том же файле JS.Этот метод возвращает список, который он получает из вызова API.Я хочу установить это значение для модели и вернуть объект модели.но моя функция возврата вызывается до того, как мой API вернет ответ.Как я могу убедиться, что функция возврата будет вызываться только после вышеперечисленного, если блок получит данные из API.
getTestData(model) {
model.name = "practice";
model.value = 2;
// this if loop is calling an API and setting up data into model.
if(this.model.form.length>0 && this.model.form[0].entityName === 'test'){
let responseList;
this.testDataService(this.model).then(response => {
responseList = response;
model.class = responseList;
});
}
return this.model;
// this return function is getting called before the api returns its data. How can i make sure this return will get called only after the above if block get the data from API.
}
This is method definition
testDataService(model) {
let profileType = "test";
let profileId = "test_profile";
let configCategory = "test";
return this.referenceDataService.getTestData(profileType, profileId, configCategory);
}