Substring in Ionic


#1

Hi, i have text like this.
“This word is very long. how to cut this sentence by word, not by character?”

For example i want to cut the text after word “cut”
“This word is very long. how to cut”

in php, i found this answer using substring. but how to do in ionic?

that text I get from database and i call that like this:
<div class="row" ng-repeat="list in list"> <p>{{list.description}}</p> </div>

Any help would be thankful!:slightly_smiling:


#2

Try break-word:normal for the CSS of your <p>


#3

i’m sorry but that’s not working bro.


#4

Try modifying your string in a controller with something similar to this:

var maxLength = (some character count that’s near your cut-off point);
var str = “your string here”;
str = str.substring(0, str.indexOf(" ", maxLength));


#5

Oh, I misunderstood your question.
Thaught you just wanted to break the line.

you can use the LimiTo filter :
https://docs.angularjs.org/api/ng/filter/limitTo

in your case : <p>{{list.description | limitTo:number}}</p>

and you can calculate your number with String.search()

http://www.w3schools.com/jsref/jsref_search.asp


#6

Thanks man! i really appreciate it!