The docs for Ember.Select use the following:
{{view Ember.Select content=foo ... }}
However, the guide uses the following
{{view Ember.Select contentBinding="foo" ... }}
Both work. Which is preferred and why?
A value that isn't wrapped in curlies is assigned as string, which matches the behavior in HTML attributes. For example, writing @isActive=true will set @isActive to the string 'true' . This is the syntax for an if statement in inline form. If the condition is true, Ember will use value at the invocation site.
Unlike in JavaScript, the empty array is also considered falsy in Ember templates. This is the syntax for an if statement in block form. If the condition is true, Ember will render the content that is inside the block.
The way to do this in Ember is by using the { {yield}} syntax. Zoey says... { {yield}} is named after a similar concept in scripting languages, including Ruby, JavaScript and Python. You don't need to understand the connection in order to use it, but if you're in the mood for a tangent, check out the yield operator in JavaScript
When you use:
{{view Ember.Select content=foo ... }}
You are creating a property called content
with the value foo
(or the value from the property foo
) in the View. In this case the Select. Given you are only assigning a value, nothing happens in the View if the value foo
changes in the 'parent' context. I use this approach when I don't need bindings. i.e. When passing a generic String
{{view Ember.Select message="Mi message" ... }}
When you use:
{{view Ember.Select contentBinding="foo" ... }}
You are setting up a binding. It basically means that you connect one property with another. When one changes the other changes too. Specifically it means that a content
property inside the View is created with the value from the property foo
. Whenever the property foo
changes in the 'parent' context the content
property in the View will change as well. The same is true in the other direction, whenever the content
property in the View is changed the foo
property from the 'parent' context will be modified.
Another nice resource.
I hope this helps you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With