Reputation: 654
I have a data item
items: [],
which i am using in a computed property that returns the lengh of that array as part of a string.
itemSummary : function() {
return this.items.length === 0 ? "No Items" : "`${this.items.length}` items selected"
}
Is it possible to do this with string interpolation....?
Upvotes: 0
Views: 251
Reputation: 2321
You almost had it in your question. I think the code should be:
itemSummary() {
return this.items.length === 0 ? "No Items" : `${this.items.length} items selected`
}
With an interpolated string you put everything inside back quotes and interpolate variables or code snippets by wrapping them in ${ ... }.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Upvotes: 1