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.

$compile: error while removing tAttr with interpolated expression during directive compile  #9236

Closed
@g00fy-

Description

@g00fy-

According to : these lines calling

tAttr.$set('foo', null);
// or 
tAttr.$set('foo', undefined);

Should remove the Attribute from the element.

This does not work with tAttrs containing interpolated expressions <h1 foo="{{bar}}">Hello</h1>.

How to replicate

See example

code:

  .directive('foo', function(){
    return {
      restrict:'A',
      compile: function(tElement,tAttr){
        tAttr.$set('foo',null); // same result with undefined
      }
    }
  })
<h1 foo="{{ bar }}">Hello World</h1>
TypeError: Cannot read property 'length' of null
    at $interpolate (https://code.angularjs.org/snapshot/angular.js:9330:28)
    at attrInterpolatePreLinkFn (https://code.angularjs.org/snapshot/angular.js:7424:33)
    at invokeLinkFn (https://code.angularjs.org/snapshot/angular.js:7549:9)
    at nodeLinkFn (https://code.angularjs.org/snapshot/angular.js:7048:11)
    at compositeLinkFn (https://code.angularjs.org/snapshot/angular.js:6441:13)
    at compositeLinkFn (https://code.angularjs.org/snapshot/angular.js:6444:13)
    at publicLinkFn (https://code.angularjs.org/snapshot/angular.js:6320:30)
    at https://code.angularjs.org/snapshot/angular.js:1485:27
    at Scope.$get.Scope.$eval (https://code.angularjs.org/snapshot/angular.js:13436:28)
    at Scope.$get.Scope.$apply (https://code.angularjs.org/snapshot/angular.js:13534:23) <h1> 

currently quick fix for apps (imho similar fix can be applied to angular Attributes + check if they contain interpolated expression):

        tAttr.$set('foo',''); // nullify (remove interpolation expression , probably trigger prematurely  registered observers / interpolation?)
        tElement[0].removeAttribute('foo');

This issue questions timing of registering interpolations (before or after compilation ?) - this should be mentioned in the docs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions