2

I have a custom my-table with the property row bound to the host component. I can put html in two ways:

<my-table [rows]="displayEntriesCount"></my-table>

and like this:

<my-table rows="{{displayEntriesCount}}"></my-table>

what's the difference?

0

1 Answer 1

2
<my-table [rows]="displayEntriesCount"></my-table>

binds the value in displayEntriesCount as is

<my-table rows="{{displayEntriesCount}}"></my-table>

does string interpolation. This means the assigned value is the stringified value of displayEntriesCount. Don't use this if you want to assign object values.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks, that's right side difference, what about left side [rows] vs row?
You can either use [] or {{}} but not both at the same time, therefore there is no left side or right side. It's always both sides at the same time. If you use one of these it is Angular2 binding syntax, if you don't use any of these it's verbatim HTML and just added to the DOM as-is without Angular2 caring about it. Actually if you have an input named rows it will add the value as string. rows="displayEntriesCount" will pass the string "displayEntriesCount"` to the input.
thanks, I'm just trying to understand the algorithm. what you're saying is that angular checks both sides at the same time? I would guess that it works first on the left side (target) and checks whether a component or DOM element has property, e.g. rows and if it does, evaluates the right side, otherwise it throws and error. Is it reasonable logic?
It definitely checks both sides if it finds either [] or {{}} and if found then it also checks if there is a property with this name on the native element or if a component or directive is instantiated on this element that has an input with this name, otherwise it throws an error like the one mentioned in stackoverflow.com/questions/35229960/…
okay, thanks. Gotta check the source code to understand the precise approach, but probably later when I get the basics :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.