0

This code is in html template inside ngFor loop

{{ (user.text.length>1)? (user.text | slice:0:1)+'...':(user.text) }}
{{user.text.length}}

user is object which has text property example below.

 user {
    name: dslkdskld,
    text: [johnd dskjsd, mark kdsdlk, joe sldk, john sdkds]
   }

String.length in this case outputs 4. Does it assume everything prior to coma 1 character ? I was hoping to get the character length of entire user.text

1
  • 1
    It's hard to say when the code has syntax errors, as the example code does. The answer guesses that you have an array because of the brackets, but without seeing where the actual quote marks are, it is just a guess. Commented Aug 19, 2019 at 11:41

2 Answers 2

1

Because user.text is not text , its array here

Try to print {{ user.text[0] }} , that will clear your doubts

What you are expecting should look like this

user {
    name: "dslkdskld",
    text: "[johnd dskjsd, mark kdsdlk, joe sldk, john sdkds]" // <--- within quotes
}
Sign up to request clarification or add additional context in comments.

Comments

0

In javascript Array and String have a length property.

So, this is Array with 4 elements:

[johnd dskjsd, mark kdsdlk, joe sldk, john sdkds]

And this dslkdskld it's a String with length 9

And you can choose which length you need in your example.

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.