Ng-include onload no longer works in angularjs 1.2.0 rc

I am using angular ng-include as follows:

main html:

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

template tpl.html:

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

controller:

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

this worked fine with angularjs 1.1.5, but no more in 1.2.0 rc 3

here is 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 cannot find an answer to this problem here.

+6
source share
3 answers

It seems that you have to do 2 things in one tag - it has ng-include and ng-controller on it. put your range inside the new one and move the ng controller to the external tag.

They could change the processing order of these attributes. In general, I think mixing them with the same tag is not a good idea.

+2
source

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

ng-include cannot be on the same element as ng-controller. In 1.1.5 it worked

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

+6
source

Because it is simply broken and there is currently no workaround.

According to change the length :

"Previously, ngInclude only updated its content, after this change ngInclude will recreate itself every time new content is added. This ensures that there is always one rootElement for all contained content, which greatly simplifies the definition of CSS styles for animations."

but instead of being improved, he seems to have been broken.

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

+2
source

Source: https://habr.com/ru/post/956099/


All Articles