Skip to content

Instantly share code, notes, and snippets.

@bmx269
Forked from ef4/positional-params.md
Created October 30, 2018 22:20
Show Gist options
  • Save bmx269/ba945310d4a751056112ffeb8ce5f324 to your computer and use it in GitHub Desktop.
Save bmx269/ba945310d4a751056112ffeb8ce5f324 to your computer and use it in GitHub Desktop.

How to use positionalParams in Angle Bracket invocation

A component with positionalParams always also has named versions of its parameters. For example, the liquid-if component from liquid-fire has this in its Javascript file:

positionalParams: ['predicate']

So these are equivalent:

{{#liquid-if isActive}}
{{/liquid-if}}

<LiquidIf @predicate={{isActive}} >
</LiquidIf>

There is a second way to use positionalParams, which is to gather a variable number of them into an array. That is how link-to works:

// notice that the right-hand value here is a single 
// name, not an array like in the previous example
positionalParams: 'params'

You can use the same trick here, but unfortunately the value you pass needs to be an array, so you may want something like ember-array-helper:

{{link-to "posts" 1}}
<LinkTo @params={{array "posts" 1}} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment