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

ngInclude behavior change from 1.2.1 -> 1.2.2 #5247

Closed
matthughes opened this issue Dec 3, 2013 · 3 comments
Closed

ngInclude behavior change from 1.2.1 -> 1.2.2 #5247

matthughes opened this issue Dec 3, 2013 · 3 comments

Comments

@matthughes
Copy link

If you have a directive on an ng-include attribute, it appears the content is not loaded prior to executing your directive's link function. In 1.2.0 and 1.2.1, the following code would have children().length == 1. In 1.2.2, the content doesn't get included until after this directive is executed. I tried setting the priority of my directive but it still gets invoked before the template has been loaded.

What is the expected behavior here? Is it defined? Do I just need to add an onload event handler in case the child gets loaded subsequent to my directive's link function being called? (I tried running this in post-link but behavior was the same).

// Full plunkr showing the problem. Just change angular version.
http://plnkr.co/edit/VWA0JTcpNDoNZkTrmllA?p=preview

<ng-include my-custom-directive src="'myTemplate.html'"></ng-include>
app.directive('myCustomDirective', function() {
    return {
      restrict: 'A',
      link: function(scope, element, attrs) {

        window.alert(element.children().length);

       }
     };
   });
@ghost ghost assigned tbosch Dec 5, 2013
@tbosch
Copy link
Contributor

tbosch commented Dec 5, 2013

Thanks for reporting!
This is a regression and was probably introduced by this commit: 0a7cbb3

In 1.2.1 we updated the element's content before executing the transclusion link function. Now we are first executing the transclusion link function and assigning the template afterwards.

A possible solution: Define two ng-include directives

  1. Does the transclude
  2. No transclude, but adds the html to children.

By this directives with lower priority would see the filled html.

Same applies to ngView (changed here: e6521e7)

@caitp
Copy link
Contributor

caitp commented Dec 5, 2013

it would be pretty easy to create those directives with minimal/DRY code, but perhaps it would be good to consider other solutions first

@ghost ghost assigned tbosch Dec 9, 2013
@tbosch
Copy link
Contributor

tbosch commented Dec 11, 2013

Discussed with @IgorMinar to fix this with secondary ngInclude and ngView directives (ngView is affected by this bug as well), as it's the simplest way to do it.

tbosch added a commit to tbosch/angular.js that referenced this issue Dec 13, 2013
The template needs to be added to the DOM before
other directives at the same element as `ngView` are linked.

Related to angular#5247.
tbosch added a commit to tbosch/angular.js that referenced this issue Dec 13, 2013
The template needs to be added to the DOM before
other directives at the same element as `ngInclude` are linked.

Fixes angular#5247.
tbosch added a commit that referenced this issue Dec 13, 2013
The template needs to be added to the DOM before
other directives at the same element as `ngView` are linked.

Related to #5247.
@tbosch tbosch closed this as completed in 30a8b7d Dec 13, 2013
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
The template needs to be added to the DOM before
other directives at the same element as `ngView` are linked.

Related to angular#5247.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
The template needs to be added to the DOM before
other directives at the same element as `ngInclude` are linked.

Fixes angular#5247.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
The template needs to be added to the DOM before
other directives at the same element as `ngView` are linked.

Related to angular#5247.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
The template needs to be added to the DOM before
other directives at the same element as `ngInclude` are linked.

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