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

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

Open wiwiwa opened this issue 13 years ago • 10 comments

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

wiwiwa avatar Sep 04 '13 03:09 wiwiwa

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

Looks like a valid bug.

petebacondarwin avatar Sep 23 '13 00:09 petebacondarwin

Getting something similar in 1.1.5 as well

samson212 avatar Sep 27 '13 19:09 samson212

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

btford avatar Oct 01 '13 22:10 btford

Not fixed by e0c134b.

petebacondarwin avatar Oct 02 '13 11:10 petebacondarwin

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.

petebacondarwin avatar Oct 02 '13 12:10 petebacondarwin

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

IgorMinar avatar Oct 03 '13 21:10 IgorMinar

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

petebacondarwin avatar Oct 03 '13 21:10 petebacondarwin

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

petebacondarwin avatar Oct 03 '13 21:10 petebacondarwin

attribute interpolation directives are currently at priority 100.

petebacondarwin avatar Oct 03 '13 21:10 petebacondarwin

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

rodyhaddad avatar Oct 03 '13 21:10 rodyhaddad