Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Invalid argument in IE when using $compile #8659

Closed
@Matsemann

Description

@Matsemann

A fiddle with a trivial example: http://jsfiddle.net/1t4crp6e/

<div ng-app="myApp">
    <div ng-controller="myctrl">
        <div test>the value is: {{testmodel}}</div>

        <br>
        <input type="text" ng-model="testmodel">
    </div>
</div>
....
link: function(scope, elm, attrs) {
            var standardText = elm.text();

            elm.html('something');

            $timeout(function() {
                console.log(standardText);
                elm.html('').append($compile('<span>' + standardText + '</span>')(scope.$parent));
            }, 2000);
        }

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)

Error: Invalid argument.
at Anonymous function (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:62:80)
at k.prototype.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:109:350)
at k.prototype.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:112:343)
at Anonymous function (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:18:158)
at d (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:34:474)
at c (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:18:66)
at fc (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:18:270)
at Xc (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:17:362)
at Anonymous function (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js:214:78)
at o (https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js:2:14725)

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions