Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 516
Jacob Avatar asked Oct 15 '13 21:10

Jacob


2 Answers

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

<span> {{mystring.length}} </span>
like image 140
Thomas Avatar answered Nov 15 '22 21:11

Thomas


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.

like image 41
Jacob Avatar answered Nov 15 '22 22:11

Jacob