New to Ember here. I am trying to figure out how to execute an action and the product of that action be used by the #with helper. Below is an example of my code:
{{#navigation-container as |navigationContainer|}}
{{#with (action navigationContainer.previousPage model) as |prev|}}
{{link-to (t 'navigation.previous') (concat 'course-run.' prev.modelName) prev activeClass="o25" title=prev.title}}
{{/with}}
{{/navigation-container}}
navigation-container is a component that exposes a few actions, one of which is previousPage. previousPage simply returns a model that I then use to create some links and use with ember-keyboard.
I'm receiving an error that the link-to can't build a route due to prev being undefined. The action is executing and returning correctly just above this with block, so I'm assuming the with block is the problem.
Thanks for any help!
I think you understood this wrong. The
withhelper does not allow you to you execute an action. The result of(action navigationContainer.previousPage model)is basically a new closure function that will executenavigationContainer.previousPagewith the first parametermodeland the next parameters are the parameters you give to your new function.So if you do something like
<button onclick={{action prv "bar"}}></button>this will result in the functionnavigationContainer.previousPageto be executed with the first parametermodeland the next"bar".If you want the result of a function in your template you have to use a computed property.