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

chromeHack method throws TypeError: optionElement[0].hasAttribute is not a function #13874

Closed
rahulbpatel opened this issue Jan 28, 2016 · 2 comments

Comments

@rahulbpatel
Copy link

Hi,

I have a custom directive that replaces with template <option ng-repeat> and this ends up throwing an exception in chromeHack on line 28664:

TypeError: optionElement[0].hasAttribute is not a function
    at chromeHack (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:28664:24)
    at self.addOption (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:28745:5)
    at self.registerOption (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:28792:12)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:29133:22
    at invokeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:9039:9)
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:8533:11)
    at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:7929:13)
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:8528:24)
    at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:7929:13)
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:8528:24) <!-- ngRepeat: item in data -->

Reproducable: always
Angular Version(s): 1.4.8, 1.4.9
Browsers and Operating System: Chrome Version 47.0.2526.111 m, Windows 10 64-bit
Reproduce the Error: http://plnkr.co/edit/UejSXqwfq320wtzN7HWG

@gkalpak
Copy link
Member

gkalpak commented Jan 28, 2016

This also happens on v1.5.0-rc.1. It's because we are calling hasAttribute on a comment.

@Narretz
Copy link
Contributor

Narretz commented Jan 28, 2016

We've actually added a number of checks for comments, but it seems like this is another corner case. Given that this uses replace I'm not too keen on working on a fix. If someone wants to give it a shot, your're welcome. ;)

gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 28, 2016
Under specific circumstances (e.g. adding options via a directive with `replace: true` and a
structural directive in its template), an error occurred when trying to call `hasAttribute()` on a
comment node (which doesn't support that method).
This commit fixes it by first checking if `hasAttribute()` is available.

Fixes angular#13874
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 28, 2016
Under specific circumstances (e.g. adding options via a directive with `replace: true` and a
structural directive in its template), an error occurred when trying to call `hasAttribute()` on a
comment node (which doesn't support that method).
This commit fixes it by first checking if `hasAttribute()` is available.

Fixes angular#13874
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 28, 2016
Under specific circumstances (e.g. adding options via a directive with `replace: true` and a
structural directive in its template), an error occurred when trying to call `hasAttribute()` on a
comment node (which doesn't support that method).
This commit fixes it by first checking if `hasAttribute()` is available.

Fixes angular#13874
gkalpak added a commit that referenced this issue Jan 29, 2016
Under specific circumstances (e.g. adding options via a directive with `replace: true` and a
structural directive in its template), an error occurred when trying to call `hasAttribute()` on a
comment node (which doesn't support that method).
This commit fixes it by filtering out comment nodes in the `addOption()` method.

Fixes #13874
Closes #13878
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.