DoneJS StealJS jQuery++ FuncUnit DocumentJS
3.14.1
5.0.0 4.3.0 2.3.35
  • About
  • Guides
  • API Docs
  • Community
  • Contributing
  • Bitovi
    • Bitovi.com
    • Blog
    • Design
    • Development
    • Training
    • Open Source
    • About
    • Contact Us
  • About
  • Guides
  • API Docs
    • Observables
      • can-compute
      • can-define
      • can-define/list/list
      • can-define/map/map
      • can-define-stream
      • can-define-stream-kefir
      • can-event
      • can-event/async/async
      • can-event/batch/batch
      • can-event/lifecycle/lifecycle
      • can-kefir
      • can-list
      • can-map
      • can-map-backup
      • can-map-define
      • can-observation
      • can-observe
      • can-simple-map
      • can-simple-observable
      • can-stream
      • can-stream-kefir
    • Data Modeling
      • can-connect
      • can-connect-cloneable
      • can-connect-feathers
      • can-connect-ndjson
      • can-connect-signalr
      • can-fixture
      • can-fixture-socket
      • can-ndjson-stream
      • can-set
    • Views
      • can-component
      • can-ejs
      • can-element
      • can-react-component
      • can-stache
      • can-stache/helpers/route
      • can-stache-bindings
        • Syntaxes
          • on:event
          • toChild:from
          • toParent:to
          • twoWay:bind
          • can-stache-bindings.legacy-syntaxes
            • (event)
            • {to-child}
            • {^to-parent}
            • {(two-way)}
            • *REFERENCE
      • can-stache-converters
      • can-view-autorender
      • can-view-callbacks
      • can-view-href
      • can-view-import
      • can-view-live
      • can-view-model
      • can-view-nodelist
      • can-view-parser
      • can-view-scope
      • can-view-target
      • react-view-model
      • react-view-model/component
      • steal-stache
    • Routing
      • can-deparam
      • can-param
      • can-route
      • can-route-pushstate
    • JS Utilities
      • can-assign
      • can-define-lazy-value
      • can-globals
      • can-key-tree
      • can-make-map
      • can-parse-uri
      • can-string
      • can-string-to-any
      • can-util
      • can-zone
      • can-zone-storage
    • DOM Utilities
      • can-ajax
      • can-attribute-encoder
      • can-control
      • can-dom-events
      • can-event-dom-enter
      • can-event-dom-radiochange
      • can-jquery
    • Data Validation
      • can-define-validate-validatejs
      • can-validate
      • can-validate-interface
      • can-validate-legacy
      • can-validate-validatejs
    • Typed Data
      • can-cid
      • can-construct
      • can-construct-super
      • can-namespace
      • can-reflect
      • can-reflect-promise
      • can-types
    • Polyfills
      • can-symbol
      • can-vdom
    • Core
    • Infrastructure
      • can-global
      • can-test-helpers
    • Ecosystem
    • Legacy
  • Community
  • Contributing
  • GitHub
  • Twitter
  • Chat
  • Forum
  • News
Bitovi

Deprecated Syntaxes

  • Edit on GitHub

Provides template event, one-way bindings, and two-way bindings.

Note: This syntax is deprecated and you should use the new syntax instead.

Use

The can-stache-bindings plugin provides useful custom attributes for template declarative event, one-way bindings, and two-way bindings on element attributes, component ViewModels, and the scope.

The deprecated bindings are as follows:

  • (event)="key()" for event binding.
  • {prop}="key" for one-way binding to a child.
  • {^prop}="key" for one-way binding to a parent.
  • {(prop)}="key" for two-way binding.

Prepending $ to a binding like ($event)="key()" changes the binding from the ViewModel to the element’s attributes or properties.

Note: DOM attribute names are case-insensitive, use hyphens (-) to in the attribute name to setup camelCase bindings.

The following are the deprecated bindings that can be used with can-stache:

event

Binds to childEvent on <my-component>'s ViewModel and calls method on the scope with the specified arguments:

<my-component (child-event)="method('primitive', key, hash1=key1)"/>

Binds to domEvent on <my-component> and calls method on the scope with the specified arguments.

<my-component ($dom-event)="method('primitive', key, hash1=key1)"/>

one-way to child

Updates childProp in <my-component>’s ViewModel with value in the scope:

<my-component {child-prop}="value"/>

Updates the child-attr attribute or property on <my-component> with value in the scope:

<my-component {$child-attr}="value"/>

Note: If value being passed to the component is an object, changes to the objects properties will still be visible to the component. Objects are passed by reference. See One Way Binding With Objects.

one-way to parent

Updates value in the scope with childProp in <my-component>’s ViewModel:

<my-component {^child-prop}="value"/>

Updates value in the scope with the child-attr attribute or property on <my-component>:

<my-component {^$child-attr}="value"/>

Note: If value being passed to the component is an object, changes to the objects properties will still be visible to the component. Objects are passed by reference. See One Way Binding With Objects.

two-way

Updates childProp in <my-component>’s ViewModel with value in the scope and vice versa:

<my-component {(child-prop)}="value"/>

Updates the child-attr attribute or property on <my-component> with value in the scope and vice versa:

<my-component {($child-attr)}="value"/>

One Way Binding With Objects

{child-prop}="key" (one-way to child) or {^child-prop}="key" (one-way to parent) is used to pass values from the current scope to a component or vice versa, respectively.

Generally, this binding only observes changes in one direction, but when key is an object (POJO, DefineMap, etc), it is passed as a reference, behaving in much the same way as the following snippet.

function component(bar) {
    // changes to bar's properties are preserved
    bar.quux = 'barfoo';

    // but replacing bar is not
    bar = {
        quux: 'hello world'
    };
}

var foo = {
    quux: 'foobar'
};
component(foo);

CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.14.1.

On this page

Get help

  • Chat with us
  • File an issue
  • Ask questions
  • Read latest news