Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I change data after an $http request?
    text
    copied!<p>I'm making a web app in angular that is primarily driven with data from remote json objects. I want to load the page with sensible default data, then request the json objects and update the controllers with this new data.</p> <p>Here's a snip from the service I made:</p> <pre><code>clickApp.factory('client', ['$http', function($http){ var logoUrl = "first"; var getConfig = function() { logoUrl = "second"; $http({method: 'GET', url: base_url+'app-config.json'}). success(function(data, status) { // this callback will be called asynchronously // when the response is available // console.log("data",data); console.log("logopre",logoUrl); logoUrl = "third"; console.log("logopost",logoUrl); }). error(function(data, status) { console.log("error",status); // called asynchronously if an error occurs // or server returns response with an error status. }); }; getConfig(); return { logoUrl: logoUrl } }]); </code></pre> <p>I have a controller hooked up to this which just fills a p tag with logoUrl for the moment. With this code, the p tag is immediately updated to "second", the log value of "logopre" is "second" and the log value of "logopost" is "third", but the controller does <em>not</em> update the p tag to "third" like I expect.</p> <p>I tried some fancy $scope.$watch statement in my controller as well, but that doesn't change the result.</p> <p><strong>edit</strong> I should note that I also tried $rootScope.$apply after the $http request but I could only get "$digest already in progress" errors.</p> <p><strong>How can I properly update this value so it's reflected in my controller after the $http request?</strong> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload