简体   繁体   中英

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM