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

Commit

Permalink
fix($compile): compile replace directives in external template
Browse files Browse the repository at this point in the history
Passing DOMNode#childNodes to compileNodes when compiling remote
template, so that directives with replace:true can be compiled.
The previous version used jqLite#contents which returned collection
that was not updated during the compilation.

Closes #1859
  • Loading branch information
danilsomsikov authored and IgorMinar committed Feb 26, 2013
1 parent e281413 commit 77c4a7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function $CompileProvider($provide) {

function compile($compileNodes, transcludeFn, maxPriority) {
if (!($compileNodes instanceof jqLite)) {
// jquery always rewraps, where as we need to preserve the original selector so that we can modify it.
// jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
$compileNodes = jqLite($compileNodes);
}
// We can not compile top level text elements since text nodes can be merged and we will
Expand Down Expand Up @@ -410,7 +410,7 @@ function $CompileProvider($provide) {
* functions return values - the linking functions - are combined into a composite linking
* function, which is the a linking function for the node.
*
* @param {NodeList} nodeList an array of nodes to compile
* @param {NodeList} nodeList an array of nodes or NodeList to compile
* @param {function(angular.Scope[, cloneAttachFn]} transcludeFn A linking function, where the
* scope argument is auto-generated to the new child of the transcluded parent scope.
* @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then the
Expand Down Expand Up @@ -992,7 +992,7 @@ function $CompileProvider($provide) {

directives.unshift(derivedSyncDirective);
afterTemplateNodeLinkFn = applyDirectivesToNode(directives, compileNode, tAttrs, childTranscludeFn);
afterTemplateChildLinkFn = compileNodes($compileNode.contents(), childTranscludeFn);
afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn);


while(linkQueue.length) {
Expand Down
29 changes: 29 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ describe('$compile', function() {
}
}));

directive('replace', valueFn({
replace: true,
template: '<span>Hello, {{name}}!</span>'
}));
}
));

Expand Down Expand Up @@ -817,6 +821,31 @@ describe('$compile', function() {
));


it('should compile template when replacing element in another template',
inject(function($compile, $templateCache, $rootScope) {
$templateCache.put('hello.html', '<div replace></div>');
$rootScope.name = 'Elvis';
element = $compile('<div><b class="hello"></b></div>')($rootScope);

$rootScope.$digest();

expect(sortedHtml(element)).
toEqual('<div><b class="hello"><span replace="">Hello, Elvis!</span></b></div>');
}));


it('should compile template when replacing root element',
inject(function($compile, $templateCache, $rootScope) {
$rootScope.name = 'Elvis';
element = $compile('<div replace></div>')($rootScope);

$rootScope.$digest();

expect(sortedHtml(element)).
toEqual('<span replace="">Hello, Elvis!</span>');
}));


it('should resolve widgets after cloning in append mode', function() {
module(function($exceptionHandlerProvider) {
$exceptionHandlerProvider.mode('log');
Expand Down

0 comments on commit 77c4a7f

Please sign in to comment.