T
T
Turtle_Onni2016-02-03 14:24:54
Angular
Turtle_Onni, 2016-02-03 14:24:54

How to wait for an http request with angularjs?

Hello!
I am using angular js and web api. The problem is this: After creating an object, you need to go to another page where you can display the entire list of these objects. I get the whole list without the new object. I assume that the server does not have time to add an object to the database.
How can this be resolved?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bromzh, 2016-02-03
@Turtle_Onni

$http.post('/api/item', item) // делаем запрос к API
  .then(function (response) { // чейним промис от $http
    // этот код начнёт выполняться только после успешного ответа от сервера
    // в параметре response будут данные ответа: HTTP-код ответа, данные из тела ответа и т.д.
    console.log(response); // обрабатываем ответ от сервера, если надо
    return $state.go('item.list'); // переход на страницу
  });

A
Alex, 2016-02-03
@streetflush

https://docs.angularjs.org/api/ng/service/$q

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question