Jacob
Jacob

Reputation: 525

AngularJS - Need help displaying current length of string in bound text input

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.

Upvotes: 8

Views: 30141

Answers (2)

Jacob
Jacob

Reputation: 525

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.

Upvotes: 1

Thomas
Thomas

Reputation: 12029

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

<span> {{mystring.length}} </span>

Upvotes: 20

Related Questions