Skip to content

Contexts

rohenaz edited this page Oct 31, 2016 · 1 revision

Each directive is bound to a specific context which specifies the object the values and actions are bound to. There are 3 types of contexts.

  1. Global - Referred to by starting with a capital letter.
  2. Model
  3. Controller

Global Context

A Global context must start with a capital letter and be accessible from the window scope. A single global context must be specified as Silica's context by name - Silica.setContext("GC") where GC is accessible through window.GC or window["GC"]. All instances of Controllers used in a data-controller expression must be a member of a Global context; the value set as the Silica context is recommended.

Model Context

A Model context can be seen as the most fine grained. Silica expressions will attempt to bind to the inner most model context first before walking up context tree to the nearest Controller Context if the property cannot be found on the model. Model contexts are created using the data-repeat="model in list" expression where model will be the reference and list is an array.

Example:

<ul data-repeat="category in category_list">
  <li>{{category.name}}</li>
</ul>

Controller Context

A Controller context is a medium grained context. Model contexts have higher priority than Controllers so any overlapping properties will go to the model. Unlike model contexts Controller contexts don't continue to walk up the Context tree if a property does not exist. Controller's should be used for all actionable expressions.

Clone this wiki locally