Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  191] [ 3]  / answers: 1 / hits: 35654  / 11 Years ago, sat, april 20, 2013, 12:00:00

I need to combine linkTo and action helpers in Ember.js. My code is:



{{#link-to 'index'}}<span {{action 'clear'}}>Clear</span>{{/link-to}}


But I would like to make this something like this:



{{#link-to 'index' {{action 'clear'}} }}Clear{{/link-to}}


And also:



<li>
{{#link-to 'support'}}
<span {{action 'myAction' 'support'}}>Support</span>
{{/link-to}}
</li>


To:



<li>
{{#link-to 'support' {{action 'myAction' 'support'}} }}Support{{/link-to}}
</li>


How can I achieve this?



Solution



Check my answer for Ember 2.0 compatible, OK for SEO solution.


More From » ember.js

 Answers
21

Ember Link Action addon



This is OK for SEO solution!



Install addon



ember install ember-link-action


Usage



You can pass closure action as invokeAction param to {{link-to}} component:



{{#link-to 'other-route' invokeAction=(action 'testAction')}}
Link to another route
{{/link-to}}


To pass parameters to action you can use:



{{#link-to 'other-route' invokeAction=(action 'testAction' param1 param2)}}
Link to another route
{{/link-to}}


Compatibility



Automated test suite confirms that addon works with 1.13 up to latest Ember 3 releases.



It works with a release, beta and canary versions of Ember.



Addon GitHub repository. Contributions are welcome.


[#78758] Friday, April 19, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;