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

regression: ng-include and ng-controller no longer work correctly on same element in -rc.3 #4521

Closed
wizardwerdna opened this issue Oct 18, 2013 · 2 comments

Comments

@wizardwerdna
Copy link
Contributor

The behavior of ng-include has changed in -rc.3, and appears to be a regression. A simplified setup is along the lines of...

<div ng-app="app">
  <div ng-include="'main.html'" ng-controller="MainCtrl"></div>
</div>

In -rc.2, this code worked as anticipated, but in -rc.3, scopes are structured in such a way that the controller is no longer working as anticipated.

For example, with main.html as

<button ng-click="addFoo()">New Foo</button>
<div>{{foos}}</div>

and mainCtrl.js as

angular.module('app').controller('MainCtrl', function(){

  $scope.foos = []

  $scope.addFoo = function(){
    $scope.foos.push('foo');
  }

});

I would expect a button to display above the text '[]', and after clicking the button, the text would show '[foo]', then '[foo,foo]' and so on. That has been the behavior in earlier versions of angular, including -rc.2. Here is a Plunker of the expected behavior, with passing tests, under rc.2.

Under the new release candidate, the scopes are structured in such a way that the display is not properly initialized and clicking the button does not trigger the addFoo() function. Here is a Plunker exhibiting the regression behavior, with failing tests, under rc.3.

Interestingly, the application will work correctly with ng-controller under both -rc.2 and -rc.3 if changes so that the ng-controller is placed alone and within a container element, such as:

<div ng-app="app" ng-controller="MainCtrl">
  <div ng-include="'main.html'"></div>
</div>

or:

<div ng-app="app" ng-controller="MainCtrl">
  <div ng-controller="MainCtrl">
    <div ng-include="'main.html'"></div>
  <div>
</div>

Clearly ng-controller is no longer working and playing well with other directives.

@caitp
Copy link
Contributor

caitp commented Oct 19, 2013

Does #4466's fix also solve the priority issues for ng-include?


I guess it does

@petebacondarwin
Copy link
Contributor

Duplicate of #4431

@ghost ghost assigned btford Nov 21, 2013
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 pushed a commit that referenced this issue Nov 21, 2013
This changes the priority of ngController to 500 so that it takes precedence
over ngInclude.

Closes #4431, #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
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.