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

"Object #<Comment> has no method 'setAttribute'" for interpolated attribute of transcluded directive #3868

Closed
wiwiwa opened this issue Sep 4, 2013 · 10 comments

Comments

@wiwiwa
Copy link

wiwiwa commented Sep 4, 2013

When a directive is set to {transcluded:'element'} and it uses a interpolated attribute value, an exception is thrown with message: TypeError: Object # has no method 'setAttribute'.

It is tested against angular.min.js v1.2.0-rc1.

Here is sample directive test page:

<!doctype html>
<html ng-app="testApp">
<head>
<script type="text/javascript" src="http://code.angularjs.org/1.2.0rc1/angular.min.js"></script>
<script language='javascript'>
angular.module('testApp', [])
  .directive('ngTest', function(){
    return {
      transclude: 'element',
      scope: { ngTest:'@' }
    }
  });
</script>
</head>

<body>
  <div ng-test="test{{var}}"></div>
</body>
</html>

Is there something wrong? thanks

@petebacondarwin
Copy link
Contributor

Here is a plunk: http://plnkr.co/edit/HyU1WlnzXHdY0oHHGZFT?p=preview

Looks like a valid bug.

@samson212
Copy link

Getting something similar in 1.1.5 as well

@btford
Copy link
Contributor

btford commented Oct 1, 2013

This may have been fixed by e0c134b. @petebacondarwin can you check against master?

@petebacondarwin
Copy link
Contributor

Not fixed by e0c134b.

@petebacondarwin
Copy link
Contributor

The problem is really that the compiler is passing the the "transclude comment node" to the rather than the transcluded node through to the being delayed and applied to the attrInterpolationLinkFn at https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L1329.
We need some way of deferring linking of this "interpolation directive" when its parent element contains a transclude:'element' directive.

@IgorMinar
Copy link
Contributor

This is the behavior that existed since 1.0.x. The issue is actually in the code. The directive that is doing element transclusion, needs to have a priority higher than attribute binding priority.

I fixed the example here: http://plnkr.co/edit/HyU1WlnzXHdY0oHHGZFT?p=preview

@petebacondarwin
Copy link
Contributor

@IgorMinar - This link is to my original plunker so is still erroring.

@petebacondarwin
Copy link
Contributor

Here is a fixed plunk: http://plnkr.co/edit/zjR1MloaxTV1iTR5ncTK?p=preview

@petebacondarwin
Copy link
Contributor

attribute interpolation directives are currently at priority 100.

@rodyhaddad
Copy link
Contributor

My solution for this was to change the priority of {{ }} (for both attributes and text nodes interpolation) to -1

I was going to send a PR, but with #4266 just submitted, I doubt that I should

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.