aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authordanilsomsikov2013-01-22 16:59:09 +0100
committerIgor Minar2013-02-25 21:44:00 -0800
commit398691beb3fc40a481afa258d181de06ec0d153c (patch)
tree1a86314e65a0778e80e3780d2b5ad6f9cd5e8df7 /test
parent7ddbde8c1c00e08a63de9701e29bf5e8bed051b8 (diff)
downloadangular.js-398691beb3fc40a481afa258d181de06ec0d153c.tar.bz2
fix($compile): compile replace directives in external template
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
Diffstat (limited to 'test')
-rw-r--r--test/ng/compileSpec.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index a03ad929..b9ed3ff9 100644
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -702,6 +702,10 @@ describe('$compile', function() {
}
}));
+ directive('replace', valueFn({
+ replace: true,
+ template: '<span>Hello, {{name}}!</span>'
+ }));
}
));
@@ -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');
); }, text: function(content) { if (typeof content == "string") { this.out.push(htmlEscape(content)); } else if (typeof content == 'function') { content.call(this, this); } else if (content instanceof Array) { this.ul(content); } }, html: function(html) { if (html) { var headingDepth = this.headingDepth; for ( var i = 10; i > 0; --i) { html = html .replace(new RegExp('(<\/?h)' + i + '(>)', 'gm'), function(all, start, end){ return start + (i + headingDepth) + end; }); } this.out.push(html); } }, tag: function(name, attr, text) { if (!text) { text = attr; attr = {}; if (name == 'code') attr['ng:non-bindable'] = ''; } this.out.push('<' + name); for(var key in attr) { this.out.push(" " + key + '="' + attr[key] + '"'); } this.out.push('>'); this.text(text); this.out.push('</' + name + '>'); if (!INLINE_TAGS[name]) this.out.push('\n'); }, code: function(text) { this.tag('div', {'ng:non-bindable':''}, function(){ this.tag('pre', {'class':"brush: js; html-script: true;"}, text); }); }, h: function(heading, content, fn){ if (content==undefined || (content instanceof Array && content.length == 0)) return; this.headingDepth++; this.tag('h' + this.headingDepth, heading); var className = typeof heading == 'string' ? {'class': heading.toLowerCase().replace(/[^\d\w_]/mg, '-').replace(/-+/gm, '-')} : null; if (content instanceof Array) { this.ul(content, className, fn); } else if (fn) { this.tag('div', className, function(){ fn.call(this, content); }); } else { this.tag('div', className, content); } this.headingDepth--; }, h1: function(attr, text) { this.tag('h1', attr, text); }, h2: function(attr, text) { this.tag('h2', attr, text); }, h3: function(attr, text) { this.tag('h3', attr, text); }, p: function(attr, text) { this.tag('p', attr, text); }, ul: function(list, attr, fn) { if (typeof attr == 'function') { fn = attr; attr = {}; } this.tag('ul', attr, function(dom){ list.forEach(function(item){ dom.out.push('<li>'); dom.text(fn ? fn(item) : item); dom.out.push('</li>\n'); }); }); } };