2

I just started to work with Angular, it seems good to implement and I am enjoying it.

I just used ternary operator in my HTML page, but it's not working and I am getting Angular parsing error

Here is the stuff which I am trying to execute.

<button class="common btnYellow viewAllText">{{data.data.bookmarks[0].category_name.length>=0 ? '{{data.data.bookmarks[0].category_name}}' : 'Recently Added'}}</button> 

What can I try next?

4 Answers 4

3

Replace this:

{{data.data.bookmarks[0].category_name.length>=0 ? '{{data.data.bookmarks[0].category_name}}' : 'Recently Added'}}

With this:

{{data.data.bookmarks[0].category_name.length>=0 ? data.data.bookmarks[0].category_name : 'Recently Added'}}

<button class="common btnYellow viewAllText">{{data.data.bookmarks[0].category_name.length>=0 ? data.data.bookmarks[0].category_name : 'Recently Added'}}</button>
Sign up to request clarification or add additional context in comments.

Comments

1

No need to nest interpolation expressions together.

Use this :

<button class="common btnYellow viewAllText">{{data.data.bookmarks[0].category_name.length>=0 ? data.data.bookmarks[0].category_name : 'Recently Added'}}</button>

Comments

1

Try this,

{{data.data.bookmarks[0].category_name.length>=0 ? data.data.bookmarks[0].category_name : 'Recently Added'}}

Comments

1

You have already used the angular expression parser so you don't have to repeat it again. You don't have to add the '' for the angular expression either.

Also, use braces to make the expressions more clearer -

<button class="common btnYellow viewAllText">
    {{ (data.data.bookmarks[0].category_name.length >= 0) ? 
    data.data.bookmarks[0].category_name : 'Recently Added' }}
</button>

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.