Component.positionalParams

positionalParamspublicstatic

Defined in packages/ember-htmlbars/lib/component.js:299
Available since 1.13.0

Enables components to take a list of parameters as arguments.

For example, a component that takes two parameters with the names name and age:

let MyComponent = Ember.Component.extend;
MyComponent.reopenClass({
  positionalParams: ['name', 'age']
});

It can then be invoked like this:

{{my-component "John" 38}}

The parameters can be referred to just like named parameters:

Name: {{attrs.name}}, Age: {{attrs.age}}.

Using a string instead of an array allows for an arbitrary number of parameters:

let MyComponent = Ember.Component.extend;
MyComponent.reopenClass({
  positionalParams: 'names'
});

It can then be invoked like this:

{{my-component "John" "Michael" "Scott"}}

The parameters can then be referred to by enumerating over the list:

{{#each attrs.names as |name|}}{{name}}{{/each}}
doc_EmberJs
2016-11-30 16:48:50
Comments
Leave a Comment

Please login to continue.