Я пытаюсь получить ответ и назначить его переменной в методе подписки, а затем использовать эту переменную для извлечения и использования извлеченных данных.Ниже мой код:
API:
public IHttpActionResult GetData(string empID)
{
empID = empID ?? " ";
try
{
using (var connection = new OracleConnection(ConfigurationManager.ConnectionStrings["Database"].ConnectionString))
{
IRepository repository = new RepositoryClass(connection);
DataCollection employee = new DataCollection();
employee.employeeData = repository.GetData(empID).ToList();
employee.CountInResponse = employee.employeeData.Count;
if (employee.employeeData != null && employee.CountInResponse > 0) {
return Ok (employee)
}
else
return Content(HttpStatusCode.NotFound, "No Employee data found for this request");
}
}
catch (Exception ex)
{
return CreateLevel3Exception(ex);
}
}
Компонент:
UpdateEmployee()
{
this.getEmployeeData()
if(
this.EmployeeOrigData.EmployeeID == this.newID
&& this.EmployeeOrigData.EmployeeName == this.newName
&& this.EmployeeOrigData.EmployeeContact == this.newContact
&& this.EmployeeOrigData.EmployeeStatus == this.newStatus
&& this.EmployeeOrigData.EmployeeAddress == this.newAdress
)
{
this.Message('info', 'Update invalid');
}
}
getEmployeeData() {
this.service.GetEmployeeData(this.addEmployeeID)
.subscribe((response) =>
{
this.EmployeeOrigData = response;
},
(err) =>
{
if (err == '404 - Not Found')
this.Message('info', err, 'Update Unsuccessful - Server error');
else
this.Message('error', 'Error', err);
});
}
Служба:
GetEmployeeData(empID: string) {
debugger;
let params = new URLSearchParams();
params.set('empID',empID)
debugger;
return this.http.get(Url, { params: params })
.map(res => res.json().employeeData)
.catch(this.handleError);
}
Здесь мне нужно получитьдетали на основе идентификатора сотрудника.Я получаю ожидаемый ответ в API, но после этого, внутри метода подписки, я не могу назначить его переменной EmployeeOrigData.Что может быть не так?