Reputation: 361
I have a component that contains a link-to. The component is more complicated, but for simplicity here:
//Component.hbs
{{#link-to link model}}{{yield}}{{/link-to}}
The problem is sometimes I will pass a model, sometimes I will not.
//Route.hbs
//providing the model
{{my-component link='chosenroute' model='chosenmodel'}}
//omitting a model - doesn't work
{{my-component link='otherroute'}}
How do I make the model argument optional?
Upvotes: 2
Views: 481
Reputation: 6221
Just put an if/else. undefined
is not a good parameter for link-to.
//Component.hbs
{{#if model}}
{{#link-to link model}}{{yield}}{{/link-to}}
{{else}}
{{#link-to link}}{{yield}}{{/link-to}}
{{/if}}
Upvotes: 2