How does data-Binding work in Angularjs?

Asked

Viewed 624 times

2

I looked for something that explains to me how the magic of data-Binding happens but I did not find.

My question is how data is propagated from view to model, how it manages to keep track of changes without setters and getters?

I searched for something in javascript that can monitor the changes of objects and variables found Object watch.(), it could be used to make data-Binding ?

  • 1

    Are you looking to create your Angularjs? type a knockoutJS?

  • @Paulohdsousa I’d just like to endender and see if there are different methods to do, I have a function of my own that doesn’t come so much to the case, that tries to make a data-Inding, but it’s just a data-tag Ference or other people call populate why not monitor the changes, I thought until this question could answer my question, but only left me with more doubt: http://answall.com/questions/97872/howfunction-o-databinding-e-dirty-check-do-angularjs

1 answer

3


Most template systems link data in only one direction, which merges with the model components, and this in turn, performs an output on your screen (this is the default data-Binding event). After this merger, some changes occur in the model or part of it (sections), which are related to this screen. However, this behavior is not automatic as it is assumed when seeing it occurring on the screen. And even worse, the changes the user makes on the screen are not reflected in the model.

The big move, is in the hands of the developer, who has to write the code that makes this sync constantly through the model and it returns this update to the screen (view).

It happens that in Angularjs, O data-Binding works a little differently:

In angular data link applications, data synchronization is automatic, between the model components and their display (screen). The way Angular implements this data binding, allows you to treat the model as a single-source of your application. What you see on the screen is a projection of the model at all times. When the model changes, the view reflects this change, and vice versa.

First the template (the packaged HTML, along with any additional markup or directive) is compiled in the browser. The compilation step produces a live display. Any changes on the screen are immediately reflected in the model, and any changes in the model are propagated to the view (screen). The model is precisely the only absolute truth of the state of your application. This is done to facilitate the programming model for the developer.

You can think of the view (screen) as a simple instant projection of your model. Because the screen is just a projection of the model, and the controller is completely separate from the screen.

It is the vision (screen) that sees the controller and sends commands to it.

Think that the model is a kind of facilitator, and the controller the guy who sends the orders to him, and what the model "facilitate", will be automatically reflected in the view.

In the Angular JS website, you can find more information about.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.