angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Textarea placeholder binding causes exception in IE11

Open provegard opened this issue 13 years ago • 23 comments

See the following fiddle:

http://jsfiddle.net/provegard/wLBwd/

While the correct placeholder appears, I also get the following stack trace in the console:

Error: Invalid argument.
   at interpolateFnWatchAction (http://code.angularjs.org/1.2.1/angular.js:6366:15)
   at $digest (http://code.angularjs.org/1.2.1/angular.js:11443:21)
   at $apply (http://code.angularjs.org/1.2.1/angular.js:11682:13)
   at Anonymous function (http://code.angularjs.org/1.2.1/angular.js:1285:9)
   at invoke (http://code.angularjs.org/1.2.1/angular.js:3616:18)
   at doBootstrap (http://code.angularjs.org/1.2.1/angular.js:1283:5)
   at bootstrap (http://code.angularjs.org/1.2.1/angular.js:1297:5)
   at angularInit (http://code.angularjs.org/1.2.1/angular.js:1246:5)
   at Anonymous function (http://code.angularjs.org/1.2.1/angular.js:20126:5)
   at trigger (http://code.angularjs.org/1.2.1/angular.js:2298:7)

IE version is 11.0.9600.16438

provegard avatar Nov 19 '13 13:11 provegard

Also happens in ie10, attempting to access nodeValue on a parentless TextNode (nodeType=3)

// in function addTextInterpolateDirective()
node[0].nodeValue = value

jamie-pate avatar Dec 03 '13 23:12 jamie-pate

May be related to https://github.com/angular/angular.js/issues/2614 ??

jamie-pate avatar Dec 04 '13 21:12 jamie-pate

Here's a temporary workaround... http://stackoverflow.com/a/20649762/1009125

aschiebler avatar Dec 18 '13 04:12 aschiebler

I still prefer capability sniffing over user agent sniffing..... See my post on #2614

jamie-pate avatar Dec 18 '13 04:12 jamie-pate

Sounds great, but which capability could be tested in this case? Ie....ugh

aschiebler avatar Dec 18 '13 05:12 aschiebler

The capability to not raise an event when the placeholder changes (like the snippet I posted in the other issue (I think it still applies)) On 17 Dec 2013 21:24, "Ender2050" [email protected] wrote:

Sounds great, but which capability could be tested in this case? Ie....ugh

— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/5025#issuecomment-30818022 .

jamie-pate avatar Dec 18 '13 05:12 jamie-pate

As the docs suggest: Easiest way to address such issues is to switch from using placeholder="{{value}}" to ng-attr-placeholder="{{value}}".

seckardt avatar Mar 28 '14 07:03 seckardt

@seckardt Cool, I didn't know about ngAttr. I wrote a custom directive as a workaround, but now I can get rid of it.

I see it's under Developer Guide / Directives in the docs, but not in the API reference. Wouldn't it be a good idea to have it there too?

provegard avatar Mar 28 '14 09:03 provegard

This isn't just placeholder binding that throws this error, though. This failed with the same behavior:

<textarea ng-model="foo">{{ foo }}</textarea>

The interpolation is redundant, so the workaround in this case was just to remove {{ foo }}, but it's kind-of annoying that the error message for this is so useless. I spent several hours troubleshooting this before finding the issue.

tomasaschan avatar Nov 11 '15 09:11 tomasaschan

This error happens also when setting the style style="padding: 3px; background: {{l.Color}}; opacity: 0.7; border-radius: 5px"

How can I substitute this expression in a way that it works with IE?

RafaelSalguero avatar Feb 10 '16 19:02 RafaelSalguero

This is a known issue with IE. As mentioned above, you can use ng-attr-style="...".

gkalpak avatar Feb 10 '16 19:02 gkalpak

Anybody getting this error just look for arguments sent for textarea.

I am using angular 1.2.28 I had the same error. <textarea ng-model="data">{{data}}</textarea> works fine in Mozilla. But, IE 11 gives invalid argument error. for this piece of code. Solution: <textarea ng-model="data"></textarea> OR <textarea>{{data}}</textarea> Looks like binding to ng-model and putting value directly causes this error which is logical also. Just thought this might be of help. Anyway, this post helped me a lot.

aditi-andurkar avatar Jul 28 '16 19:07 aditi-andurkar

This error happens, because (for whatever reason) IE temporarily converts <textarea placeholder="{{'foo'}}"></textarea> to <textarea placeholder="{{ 'foo' }}">{{ 'foo' }}</textarea>. This adds the implicit text-interpolation directive on the {{ 'foo' }} TEXT_NODE, but by the time Angular tries to set the TEXT_NODE's value, it has been removed again by IE.

And trying to set the nodeValue of a parentless TEXT_NODE (e.g. parentlessTextNode.nodeValue = 'foo') throws in IE.

I think this is not an Angular-related issue and (taking into account that there is a reasonable workaround - using ng-attr-placeholder) we should just document it and move on.

gkalpak avatar Jul 29 '16 09:07 gkalpak

This bug report seems relevant. It seems that the placeholder value would stick around as <textarea>'s content. They have fixed that (at least in latest IE11), but not 100%; i.e. the placeholder text does appear as content, albeit only temporarily.

gkalpak avatar Jul 29 '16 10:07 gkalpak

In my case, I dont even have a placeholder. I just have something similar to this <textarea ng-model='$parent.freetext.text' >{{dataobject.text}}</textarea> and I still get the interpolation error. Any thoughts/solution is greatly appreciated. FYI, I am using 1.5 version of angularjs...

LotusShiv avatar Sep 10 '16 02:09 LotusShiv

@LotusShiv, don't put any value in your text area. If you want to initialize it, put the value on the model instead.

gkalpak avatar Sep 10 '16 06:09 gkalpak

So gkalpak - in my case I need to bind to the existing value from a WebAPI call and also allow user to edit the text area. Hence I had the ng-model and textarea value setting. Now the way I understood from your response is that - I have to set the value coming from the WebAPI call to a $scope object variable and use the same $scope object variable for setting the edited contents as well. Am I understanding you correctly? Again thanks in advance for any suggestions/solution. Sample code is appreciated too....

LotusShiv avatar Sep 11 '16 18:09 LotusShiv

Addendum to my previous comment, I did exactly as I explained of what I understood from gkalpak 's suggestion and it worked. Thanks gkalpak, works just fine in IE 11. Saved a lot of heartache.... :) after days of trying so many other tips and tricks ....

LotusShiv avatar Sep 11 '16 18:09 LotusShiv

As many of the people above have mentioned this error is in fact a usage error, in my case it was not in a textarea but the comments above really helped. Thanks everyone :) Will put my specific problem and fix below for others that might be in the same situation.

Not working; <a concat="[result.responsible.Contact.firstName, result.responsible.Contact.lastName]">{{responsibleFullName}}</a> Working; <a>{{result.responsible.Contact.firstName}} {{result.responsible.Contact.lastName}}</a>

Lelli avatar Nov 03 '16 09:11 Lelli

Also encountered this problem, for me it was template attr in directive. When you use just template: '{{field}}' you will get this error. For me I was replacing element HTML with compiled content, so the solution was to remove {{field}}and leave it just with template: '', but this is strange bug and debugging it in IE is pain :(

Pirozek avatar Oct 16 '17 11:10 Pirozek