6

I am using angular's ng-include like this :

main html:

<span ng-include="'tpl.html'" ng-controller="TplCtrl" onload="loadMe()"></span>

template tpl.html:

<h2>{{ tplMessage }}</h2>

the controller:

$scope.loadMe = function () {
        $scope.tplMessage =  'template';
    }
})

this was working fine with angularjs 1.1.5 but not anymore in 1.2.0 rc 3

here is a plunkr : http://plnkr.co/edit/zYRevS?p=preview

any idea how to make this work with 1.2.0 ?

edit: i saw this : https://github.com/angular/angular.js/issues/3584#issuecomment-25279350 but can't find the answer to this problem here.

François Romain
  • 13,617
  • 17
  • 89
  • 123

3 Answers3

6

ok i found the answer here : https://github.com/angular/angular.js/issues/3584#issuecomment-25857079

ng-include can't be on the same element as ng-controller. In 1.1.5, it was working

here is a working updated plunker with an html element wrapping the ng-include: http://plnkr.co/edit/CB8jec?p=preview

François Romain
  • 13,617
  • 17
  • 89
  • 123
2

Because it's just broken, and there is currently no workaround.

According to the change long:

"previously ngInclude only updated its content, after this change ngInclude will recreate itself every time a new content is included. This ensures that a single rootElement for all the included contents always exists, which makes definition of css styles for animations much easier."

but instead of being improved, it appears to have been broken.

According to the comments here the current implementation is broken.
Other sources will tell you the same.

Community
  • 1
  • 1
Scott Solmer
  • 3,871
  • 6
  • 44
  • 72
2

It seems to have to do with you mixing 2 things on the same tag - it has both ng-include and ng-controller on it. put your span inside of a new one and move the ng-controller to the outside tag.

They might'of changed the order in which these attributes are processed. In general I think mixing them on the same tag is not a good idea.

mfeingold
  • 7,094
  • 4
  • 37
  • 43
  • we answered the same thing at the same time :-). yes this is the reason (there is a link to plunker with the working solution in my answer below) – François Romain Oct 16 '13 at 18:50