0

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....?

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.