0

I am wondering how AngularJS 'saves' its data/model. Does it actually save it or.. how does it work?

We are using different methods to retrieve JSON data. In other frameworks like jQuery we had to think about how to store data locally, i.e. when we want to provide a sorting possibility. In Angular this seems different, it seems to do all that for us out of the box.

Is it that Angular displays everything how it is supposed to be and looks at changes, reads in the displayed data in and then displays it differently or does it use a local storage to save the raw json.. and work from there? (This would limit the amount of data we can feed)

Here is a simple code-example:

$http.get("url-to-json")
    .success(function(returnedData) {
    $scope.search_result = returnedData['search_result'];
})

From there I can just use:

<div ng-repeat='result in search_results | sortResult:"price":sorted' id="res_<% result.id %>" class="result">
    Product: <% result.name %>
</div>

I am riddled how Angular still knows the data and doesn't have to load it again from the external source.

Do you know?

hogan
  • 1,434
  • 1
  • 15
  • 32

1 Answers1

0

There is a lot more that goes into it, but essentially its all stored in local memory. Angular creates an object of all your scope properties. When you do data binding in angular you are registering an event listener and when that event is called angular loops through this object detecting if something has changed, and if so updates the object accordingly. Each time an update occurs it returns to the loop to check if anything else has been updated. This is what is referred to as the $digestLoop.

SOURCE

The ng-book

richbai90
  • 4,994
  • 4
  • 50
  • 85