Posts

Showing posts with the label http post

Angular promises

Image
I have been struggling to understand Angular promises for months, and I finally found an answer on Stack Overflow that explains them really well. There's also this really helpful cartoon which has a nice story explaining the fetching of data . However, the Stack Overflow answer was what really did it for me, and fully deserves its current status of 383 upvotes. The problem The problem that promises set out to solve is that when you make asynchronous calls to a server where the results of one call are dependent on another call, you need to return the results in the order of your dependencies, not in the random order that will happen depending on which server call returns its results first. Example Say I have a page where users can subscribe to or unsubscribe from email mailing lists and RSS feeds. The data displayed on the page is an amalgam of two different services fetching data from two different servers. The unsubscribe action and the subscribe action both send calls to the se...

Submit a post request from an Angular modal and refresh the main page

I have a main controller with some data (fetched by $http.get), and when you click on one item, it pops up a modal with more details. In my modal, there is a button to modify the data (sent by $http.post) which then closes the modal and needs to tell the parent controller to refresh the data, because it has been modified by the event in the modal. NB: if you use my solution - don't forget to add Angular UI bootstrap to your main controller as follows: var myApp = angular.module('myApp', ['ui.bootstrap']); HTML <!--MODAL WINDOW for item details --> <script type = "text/ng-template" id = "itemModalContent.html" > < div class = "modal-dialog ng-hide=" hidden "> < div class = "modal-content" > < div class = "modal-header" > < button type = "button" class = "cancel rig...