8

I just started with Angular a couple days ago so simple stuff still occasionally gets the best of me. I'm trying to show the current character count of a textarea. I thought surely this should work:

<textarea ng-model="mystring"></textarea>
<br>
<span> {{mystring.length()}} </span>

It doesn't work at all.. But why? And how do I accomplish this?

If I remove ".length()" the content of the textarea is showing up like it should so the binding is obviously working...

EDIT: So it works in chrome etc but not in IE, or more specifically, the embedded browser control in a .Net winform. hooray.

2 Answers 2

20

The length of a string is a property in javascript. So this should work

<span> {{mystring.length}} </span>
Sign up to request clarification or add additional context in comments.

3 Comments

You're right, and that is what I expected to work. Turns out it's only not working in this embedded browser control (IE pretty much). Any Ideas?
Did you try it with property access as well? (Your example seems to call the length() method, which should yield an error.)
Problem is that after page was loaded the value 0 from {{mystring.length}} variable will be invisible.
1

The .Net browser control acts like IE7 by default so lots of things don't really work. In an attempt to remedy this I added a registry entry as indicated in this MSDN article to force the browser to act like IE9 but still had the same problem with string.length in the expression as well as a new "object doesn't support this action" error being thrown.

At this point I gave up and decided to use this WebKitdotNet control. It adds 30 or so MB to my install size but it actually works without having to change a lot of javascript or muck about in the registry.

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.