-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Invalid argument in IE when using $compile #8659
Comments
Update: The error message here wasn't that helpful. When doing it not inside an anonymous function this is the message:
|
Seems to throw one error, it has issues assigning an interpolated value to the node (not sure if it's the subsequently compiled <span>, or if it's the <div>). If you can figure out what it's trying to assign to I don't think this is breaking any of your other watches though (i'd have to double check), but it looks like $exceptionHandler is dealing with this nicely |
It will rethrow the error each time you change the value in the input box. It happens also in my second example (but this time everything breaks in IE), so it may not be the span? Not sure how to debug this? It happens the next digest as far as I can tell, so difficult to track with my limited experience since it happens so much between my code and the error. I agree, it seems to work as it should (the first example) except for all the errors. Why doesn't the second one work, though? Any ideas for a better way to compile stuff inside a directive? |
Don't compile stuff inside a directive, this isn't what you want to do unless you really understand the html compiler |
Any ideas for a different way to achieve what I'm trying? I have a button, which the directive is applied to. The directive watches a value set by the controller, that changes the content of the button. So originally the content of the button would be: My code is here, but it contains some other stuff as well. |
Transcluding it, and then just show/hide the original binding and show something else when needed seem to work fine. |
I've noticed that in my case returning from textInterpolateLinkFn, when node.nodeValue is an empty string fixes all problems in IE:
I can describe my use case or create a runnable test case if needed. |
I've noticed this behavior in my app. Not certain how to reproduce it, but based on this stack overflow question it appears to be an issue when the node has no child nodes and therefore Here's a jsbin based on that Stack Overflow question which shows the issue (when using IE). |
I was able to resolve my issue by going from this kind of binding: <span>{{foo}}</span> to using the directive version: <span ng-bind="foo"></span> Would like to not have to do that if I can help it though :-) |
related issue angular-ui/ui-select#276 |
Had the same issue on the dynamic text of a button ; solved by kentcdodds' ng-bind workaround. |
While there is a workaround. A fix would be welcome :) |
I ran into a variant of this issue as well with Angular 1.2.15 with IE 11. It was caused by this dynamic button text:
The error was caused by the addTextInterpolateDirective function last compile line of:
When console logging the node, it was a parentless text node and would error out in IE. |
I am also eagerly waiting for a fix to this issue. Meanwhile, changing this:
to this (notice the
fixes it for now. Logic: Downside: template code pollution. |
Any updates on this issue? |
How about we just use this 3 line fix that I've posted and be done with it ? |
Also experiencing this issue, any word on a timescale for the fix proposed to be implemented? |
I'm seeing the same issue. Is this going to be fixed soon? |
If you're using webpack, I added this loader to solve this problem as per @siemiatj's response: https://www.npmjs.com/package/falafel-loader |
This approach fixed it for me.
|
Would love to see an official fix for this as well. We are using this for a large-scale Angular app and the interim solutions will be a pain to use. |
+1 on that issue here, we also have a very large AngularJS app to maintain. |
For people experiencing this issue, I would recommend you simply use the work-around of |
Hey |
Please correct me if I am wrong... To me the observed behavior (the 'Invalid argument' error) does not seem to be a bug in IE or in angular at all. Lets examine the code in the opening post:
(You could also do elm.html("") or elm.empty()) So what happens here?
So to me it seems to not be a bug in IE or in angular, but rather in the code presented in the opening post. However it's not always possible to let angular manage the DOM. So the solution would be to create a child scope for the DOM element that contains the {{testmodel}} expression. Well... |
@rent-a-developer Thanks for investigating, I think you are right that this is actually expected behavior, it's just that many browsers tolerate it, while IE does not. @lgalfaso Do you agree that this is actually expected behavior? |
I agree with @Narretz - that if you are going to modify the contents of the node and potentially recompile then you should be doing this in the |
Based on the explanations of @rent-a-developer and @petebacondarwin and my recommendations, I will close this issue as "wontfix" |
I recently came across the same issue rendering a kendo treeview with an angular template. The template used to be:
Adding an
|
+1 |
I'm going to lock this issue. Please see the explanations in #8659 (comment) and the recommended course of action in #8659 (comment). |
A fiddle with a trivial example: http://jsfiddle.net/1t4crp6e/
Wait 2 secs, see the content of directive change to a binding. In Firefox, everything works. In IE it works, but it throws a lot of errors in the console.
(Don't worry about what I'm doing here, I just made a small example showing the issue)
However, most of my tries of actually writing this worked in all browsers except IE. For instance, if I remove the span in the compile, and instead of elm.text() use elm.contents().
http://jsfiddle.net/1t4crp6e/1/ Only changed line 13 and 19 in the js, breaks horribly in IE. It's almost impossible to compile stuff in IE.
Am I doing something wrong? And any workarounds?
The text was updated successfully, but these errors were encountered: