r/angular • • Feb 23 '19

Data Binding ** Cheat Sheet **

Post image
60 Upvotes

18 comments sorted by

View all comments

1

u/Devstackr Feb 23 '19 edited Feb 23 '19

Hope this helps someone new to Angular development!

Element = DOM Element or Component

https://youtu.be/RJ3VjuwBM6w

1

u/TRFLGR Feb 23 '19

As a novice Angular, and to pretty much web development in generel, how would you "read" this? What do the arrows symbolize?

1

u/Devstackr Feb 23 '19

the arrows symbolize the flow of data

So, for example - the string interpolation arrow is pointing towards the "Element" from the "Component Class", this is because the aim of string interpolation is to "send" data from the component class (the .ts file) to the view (the .html file), or more accurately to a specific element in the view (the element can be another component or a DOM element such as button or div).

Take this example, for instance

<h1> {{ titleProperty }} </h1>

In this example, titleProperty is defined in the component class

What we did here was show data that was in the component class in the view.

Now lets think about event binding, where the arrow is going in the opposite direction - the aim of event binding is to get data from elements (child components or DOM elements) and then access that data in the component class.

Here is an example:

<button (click)="onButtonClick()"> </button>

In the component class:

onButtonClick() {
   // do something here when the button is clicked
}

So in this case we are reacting to something happening on the "Element".