0

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...

1 Answer 1

2

length is not a function.

Replace

    if(str.length() < wrappedLength)
        {
            return strText;
        }

With

    if(str.length<wrappedLength)
        {
            return strText;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

I had just figured that but didn't get a chance to save face... :) I'll give you the point though.

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.