javascript - AngularJS binding response from server not updating in view -


I am developing a mobile application, I try to relay the message in the view returned from the server after the AJAX call The time had to face a problem. The idea is to display the message after the user clicks on the "Refresh" button.

Binding is not working properly as I expected. This is not showing the current message to the user, but the last click of the refresh button was obtained from this, for the first time when the user clicks the button after loading the view, nothing happens ... I can not understand I'm not sure that the visual update is instantaneous, but the user only changes when the user clicks again.

Here is a simplified version of my code:

HTML:

  & lt; Span ng-model = "rec" & gt; {{Rec}} & lt; / Span & gt; & Lt; Button ng-click = "getNew ()" & gt; Refresh & lt; / Button & gt;  

Javascript:

  $ scope.rec = window.localStorage.getItem ('content'); $ Scope.getNew = function () {$ .ajax ({... success: work (result, text position, xhr) {... window.localStorage.setItem ('content', result.content); $ scope Rec = Window.localStorage.getItem ('content');}}, error: function (xhr, textStatus, errorThrown) {...}}); };  

I know that Ajax calls are successful every time because the scene is updated, but one step is delayed when it should be. Thanks for the help in advance!

There is no digest cycle after the AJAX call is over, so the view update is not found if you < The view will be updated when you use the $ http service instead of code> $ .jax .

The code will look like this:

  $ http ({method: 'GET', url: '/ someUrl'}). Success (function (data, position, header, config) {window.localStorage.setItem ('content', data); $ scope.rec = data;}) error (function (data, position, header, config) {. .});  

Of course you have to inject your controller to $ http .


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -