5

I am reading educational data from facebook and showing it to my page directly. I find some string too long so i want to put ... after certain number of character in angularjs.

ex

jeevan sadhana english medium high school 08

to

jeevan sadha..
2

5 Answers 5

6

There are two possible solutions.

  • Using pure CSS, use text-overflow: ellipsis; along with overflow: hidden;. Obviously, your element will have to be fixed width.
  • You can use an Angular module such as angular-truncate.
Sign up to request clarification or add additional context in comments.

Comments

3

Create filter in angular code.

Working http://jsfiddle.net/tUyyx/

Use filter code give in fiddle.

Then filter your content like :

{{ name | truncate : 25}}

Comments

1

If you want to add ellipses after n number of lines then we can do this using Jquery.dotdot plugin Check this link Adding ellipses after n-bumber of lines in AngularJs

1 Comment

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
0
maxLength = 10;
str = str.length > maxLength ? str.substr(0, maxLength) + '...' : str;

2 Comments

I don't know man. Sure, this works. But first, you need to write some unnecessary JavaScript and second, you lose the original string completely.
Oh yes, it is definately destructive in that regard. In terms of unnecessary JS, I beg to differ on that point (you'd probably put it as a $scope variable though), because it could be reused throughout the scope of the controller and made dynamic if one were to turn this piece of code into a filter and pass the length into said filter. That way, you wouldn't loose the original string. However, should one want to do that, angular-truncate is probably the best bet as suggested by Zopieux.
0

I used these three css stylings and it worked for me:

text-overflow: ellipsis; overflow: hidden; white-space: nowrap;

Also ensure that the width is fixed (in px or %age).

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.