angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$compile return wrong $element

Open pro85 opened this issue 13 years ago • 4 comments

Start with 1.2.0 version $compile("<div ng-controller="controller" data-ng-include="templateUrl"></div>")($scope); return wrong $element in controller. $element is Object Comment(data: " ngInclude: templateUrl ").

pro85 avatar Nov 30 '13 08:11 pro85

Did you retype the code example? Because you haven't escaped the inner double-quotes or used single quotes:

$compile('<div ng-controller="controller" data-ng-include="templateUrl"></div>')($scope);

ericclemmons avatar Dec 01 '13 16:12 ericclemmons

Off cause code is $compile('<div ng-controller="controller" data-ng-include="templateUrl"></div>')($scope); If i add ng-include as child element all ok. $compile('<div ng-controller="controller"><div data-ng-include="templateUrl"></div></div>')($scope);

pro85 avatar Dec 01 '13 17:12 pro85

This functionality is by design. This is a quote from Angular's source. "using ng-include on an element with additional content does not make sense..." ngInclude trancludes the entire 'element' and replaces the transcluded clone with an element that is directly correlated to the template ngInclude fetches from the http request. This means the the orignal element is not relevant anymore once ngInclude is added to a DOM node.

joshkurz avatar Dec 01 '13 19:12 joshkurz

it's hard for me to judge from this what the actual issue is. we tweaked ngController+ngInclude priorities to ensure that ngController runs before ngInclude and so that we construct the controller just once.

This happened in one of the 1.2.x patch releases.

If you are still having a problem please create a new issue with a link to plunker reproducing the issue + description of the actual vs expected behavior.

IgorMinar avatar Dec 21 '13 06:12 IgorMinar