API
Code | Detail |
---|---|
id
|
Sets the id of a component. This is just the normal HTML id, not actually part of ichigo at all. It deserves to be called out here though if you nest components.
If you have a very simple case, one component by itself, then you are OK just using i-v replacements by themselves. But in most use cases, components are nested inside other components, and if you are applying components to areas static HTML, it's necessary to indicate which component a given tag references, otherwise the wrong component will be updated. This is handled by referencing the id of the component, using
See the following example:
If you intend to have nested components, you should assign ids to all replacements. It's easy to create a scenario like this obviously bad one: If you are nesting components, always bind from outermost to innermost. When you create a component, its innerHTML is replaced, meaning that any previous components having references to elements in that HTML are now referencing nonexistent elements. |
i5_text
|
Sets the innerHTML, escaping HTML. |
i5_html
|
Sets the innerHTML, not escaping HTML. |
i5_value
|
Sets the value of the form field (only works for form fields). It works even on form fields, such as textarea, that don't have a value attribute. |
i5_input
|
Binds input events on the form field to the BoundComponent.write() method. If the view model property (which is optional) is set, it indicates the field that should be updated. |
i5_target
|
Sets additional properties to be updated by BoundComponent.write(). |
:input: or i5_input: or i5_input_value
|
Sets up two-way binding on a view model property. A shortcut for
|
i5_target
|
Binds input events on the form field to the BoundComponent.write() method. |
i5_attr:some_attribute_name or i5_attr_some_attribute_name
|
Sets the attribute named some_attribute_name. |
i5_bool:some_attribute_name or i5_bool_some_attribute_name
|
Adds the boolean attribute named some_attribute_name if the view model property is truthy, else removes it. |
i5_bool-:some_attribute_name or i5_bool0_some_attribute_name
|
Removes the boolean attribute named some_attribute_name if the view model property is truthy, else adds it. |
i5_style
|
Sets the style string. |
i5_class
|
Sets the className string. |
i5_switch:some_class_name or i5_switch_some_class_name
|
Adds the class named some_class_name if the view model property is truthy, else removes it. |
i5_switch-:some_class_name or i5_switch0_some_class_name
|
Removes the class named some_class_name if the view model property is truthy, else adds it. |
i5_if
|
Hides the object (using CSS display:none) if the view model property is truthy, else shows it. If it was previously set to, for example, display:block, then that will be restored. If it wasn't, then Ichigo can't read your mind so hopefully you don't need a specific display property. You could complain to the W3C to split visibility and blocking into two properties, but you'd do better to just use a class. |
i5_if- or i5_if0
|
Hides the object (using CSS display:none) if the view model property is falsy, else shows it. |
i5_loop
|
Repeat the contents of the element once for every item in the view model iterable. After each item is added, the method loopPostProcess()
is called taking these inputs:
|
i5_loop:null or i5_loop_null
|
Repeat the contents of the element once for every item in the view model iterable. After each item is added, the method loopPostProcess() is NOT called. |
i5_item
|
(optional) After content has been repeated using i5_loop, the i5_loop selector indicates the HTML object that should be converted to a component by loopPostProcess(). The property of the i5_item attribute does not matter. If not included, then loopPostProcess() grabs the first, topmost level element. In 99.9% of cases, this is a fine, so i5_item is not needed. |
i5_event (eventName)="method"
|
Calls addEventListener(eventName, component[method].bind(component)). |
Type definitions