Reputation: 473
I'm trying to wrap my output that I know won't have any spaces (it's an email address). I'm using a function we already have that works. What it does is takes a string, and a wrap length, and cuts the string every time it sees that length and inserts a br tag.
It was a regular javascript function before, so I figured it would work just as well as an angular function. The problem is that it thinks "Number is not a function" when I try to use it.
$scope.data = {
str1:"reallyreallylongstringohwowthisislongwhyarenttherespacesjeezcanthisstringgetanylongerohithinkitsdonenow",
str2:"thisstringisntthatlong",
str3:"alrightthisoneslongagainreallyreallyreallyreallyreallyreallyreallyreallyreallylong"
}
$scope.wrapText = function(strText, wrappedLength){
var outStr;
if(strText!=null){
var str = strText.trim();
if(str.length()<wrappedLength)
{
return strText;
}
else
{
outStr = str;
var temp = outStr.split("(?<=\\G.{"+wrappedLength+"})");
outStr="";
for(var i = 0; i<temp.length;i++){
temp[i]+="<br>";
outStr+=temp[i];
}
return outStr;
}
}
else
return strText;
};
and on the html page:
{{wrapText(data.str1, 50)}}<br>
{{wrapText(data.str2, 50)}}<br>
{{wrapText(data.str3, 50)}}<br>
The output i get is "undefined" for each one, and the error message is this one
I've created a fiddle for this as well.
Am I missing something? I don't see where I'm trying to use a number as a function... Really confused...
All the other things I've found for this error message have to do with special things people are trying to use with angular... I'm just trying to use basic functionality...
Upvotes: 0
Views: 419
Reputation: 3327
length
is not a function.
Replace
if(str.length() < wrappedLength)
{
return strText;
}
With
if(str.length<wrappedLength)
{
return strText;
}
Upvotes: 2