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

ng-controller is not working in conjunction with ng-include in 1.2.0-rc.3 #4431

Closed
ValeriiVasin opened this issue Oct 15, 2013 · 21 comments
Closed

Comments

@ValeriiVasin
Copy link

When we are trying to declare something like

<div class="hello" ng-include src="'hello'" ng-controller="HelloCtrl"></div>

After hello template is inserted - HelloCtrl will not be applied for template.

Demo: http://jsbin.com/ekelOMI/2/edit

In 1.2.0-rc.2 everything works fine.

@rahim
Copy link

rahim commented Oct 15, 2013

I've also just been bitten by this, like you I found the issue was introduced between 1.2.0-rc.2 and 1.2.0-rc.3

@kdekooter
Copy link

confirmed. just reverted to RC2

@kdekooter
Copy link

@marcghorayeb
Copy link

I, too, can replicate this.

@dgieselaar
Copy link

Happening for me as well. What I think is happening: The template is attached to the parent controller before the controller on that element is initiated, creating a sibling relationship instead of child-parent.

@wizardwerdna
Copy link
Contributor

Also noted in #4521

@andr2
Copy link

andr2 commented Oct 23, 2013

@asilluron's fix works. Thanks!

@ghost
Copy link

ghost commented Nov 1, 2013

seconded to @asiluron's fix, changing controller's priority to 1000

@ryanseddon
Copy link

To monkey patch this in the mean time I've decorated ngController to change the priority:

$provide.decorator('ngControllerDirective', ['$delegate', function($delegate) {
    $delegate[0].priority = 900;
    return $delegate;
}]);

@dgieselaar
Copy link

Genuine question: why was this not addressed for 1.2.0? Is this not supposed to work, or is this setup not recommended? We've been using this a lot.

@petebacondarwin
Copy link
Member

This issue was introduced with this commit: 5eb1fb6
As you can see the change was to raise ngInclude's priority from 0 to 1000, athough more recently it was lowered to 400. In any case this is higher than the default of 0, which is ngController's priority.

This explains why increasing ngController's priority to 1000 fixes the issue. I believe that this is the right solution but the question is what is the best priority for ngController?

@totof3110
Copy link

Stumbled on this issue too, same use case (declaring controller and include on the same element).

Nesting the include inside the controller is a workaround but it messes up the DOM structure:

<div ng-controller="HelloCtrl">
    <div class="hello" ng-include src="'hello'"></div>
</div>

A fix would be greatly appreciated. :)

@hirro
Copy link

hirro commented Nov 14, 2013

Thanks totof3110, works perfectly, made my day!

@ds82
Copy link

ds82 commented Nov 15, 2013

sadly, not fixed in 1.2.1 either

@marcghorayeb
Copy link

Priority is also broken with ng-show and ng-include - the partial defined in an ng-include will always be displayed even if the no-show condition is false

  • this happens on 1.2.0 rc2 too

@alexdn
Copy link

alexdn commented Nov 19, 2013

@totof3110 Agree with you, that workaround works, but DOM is not clear.

@ghost ghost assigned btford Nov 21, 2013
@micronull
Copy link

В 1.2.1 не работает (not work):
http://jsbin.com/iJIJIyeL/2/edit

@bullgare
Copy link
Contributor

I reported that again. Did not see this one.
It's still there in 1.2.1
#5067

@btford
Copy link
Contributor

btford commented Nov 21, 2013

This fix will be in 1.2.2.

btford pushed a commit to btford/angular.js that referenced this issue Nov 21, 2013
This changes the priority of ngController to 500 so that it takes precedence
over ngInclude.

Closes angular#4431, angular#4521
@btford btford closed this as completed in 6288cf5 Nov 21, 2013
prigaux added a commit to EsupPortail/esup-smsu-api-admin that referenced this issue Jan 2, 2014
need workaround for ng-controller + ng-include ( angular/angular.js#4431 )
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
This changes the priority of ngController to 500 so that it takes precedence
over ngInclude.

Closes angular#4431, angular#4521
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
This changes the priority of ngController to 500 so that it takes precedence
over ngInclude.

Closes angular#4431, angular#4521
@wcorderolara
Copy link

Hello, when I use the next code:

I get this error: Error: [$injector:unpr] http://errors.angularjs.org/1.2.21/$injector/unpr?p0=highlightFilterProvider%20%3C-%20highlightFilter

and my browser crashes, as if would be in an infinite loop.

some body can help me.

@caitp
Copy link
Contributor

caitp commented Aug 18, 2014

@WalterC87 could you post a reproduction to plnkr.co or jsbin.com? thanks!

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