0

In an Ember Component it is possible to define a positionalParams property so that parameters passed as positional params become available as properties. E.g:

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

when it is invoked: {{my-component "John" 38}} the property name has the value John and de property age has the value 38.

I would like to have the opposite behavior but I cannot find whether this is possible. The behavior I'm looking for is like following:

Instead of passing a number of positional params ({{my-comp param1 param2}}) I would like to pass an array property ({{my-comp positionalArguments=myArray}}) because it can be of a dynamic size.

I'm not only looking for this behavior at components, but also helpers: {{ concat firstName " " lastName }} should become {{ concat positionalArguments=myArray }}. The helper should get the same params-array as first argument in both cases.

Willem de Wit
  • 8,604
  • 9
  • 57
  • 90
  • `MyComponent` is using `reopenClass` method for defining `positionalParams`. so this is specific to class `MyComponent`. I would say defining positionalParams dynamically its not possible. – Ember Freak Oct 26 '16 at 08:51

1 Answers1

1

UPDATE After my misunderstood is resolved:

You want to have a spread operator. You may look this discussions 1, 2. For now, you can get the array and do the assignment at init. Also have a look at this SO discussion.

OLD Answer

So don't use array brackets in your positional parameter definition:

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

Use it like that:

{{my-component 2 'a' 'b'}}
{{my-component 2 'a' 'b' 4 'c' 7}}
Community
  • 1
  • 1
ykaragol
  • 6,139
  • 3
  • 29
  • 56
  • I would like to use it the other way, by passing a property reference (which is an array) and it should be interpreted as the positional parameters. – Willem de Wit Oct 26 '16 at 08:53