Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.Select content vs contentBinding

Tags:

ember.js

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?

like image 745
Gregg Avatar asked Feb 02 '14 02:02

Gregg


People also ask

What is @isactive in ember if statement?

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.

Is an empty array falsy in Ember templates?

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.

How do I yield data in Ember?

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


1 Answers

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!

like image 158
edpaez Avatar answered Oct 06 '22 23:10

edpaez