mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 19:40:56 +08:00
fix(compiler): corrects component transclusion on compilation root.
Closes# 2155
This commit is contained in:
@@ -534,7 +534,7 @@ describe('$compile', function() {
|
||||
expect(div.hasClass('log')).toBe(true);
|
||||
expect(div.css('width')).toBe('10px');
|
||||
expect(div.css('height')).toBe('20px');
|
||||
expect(div.attr('replace')).toEqual('');
|
||||
expect(div.attr('replace')).toEqual(undefined);
|
||||
expect(div.attr('high-log')).toEqual('');
|
||||
}));
|
||||
|
||||
@@ -856,7 +856,7 @@ describe('$compile', function() {
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(sortedHtml(element)).
|
||||
toEqual('<div><b class="hello"><span replace="">Hello, Elvis!</span></b></div>');
|
||||
toEqual('<div><b class="hello"><span>Hello, Elvis!</span></b></div>');
|
||||
}));
|
||||
|
||||
|
||||
@@ -868,7 +868,7 @@ describe('$compile', function() {
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(sortedHtml(element)).
|
||||
toEqual('<span replace="">Hello, Elvis!</span>');
|
||||
toEqual('<span>Hello, Elvis!</span>');
|
||||
}));
|
||||
|
||||
|
||||
@@ -1077,7 +1077,7 @@ describe('$compile', function() {
|
||||
|
||||
var div = element.find('div');
|
||||
expect(div.attr('i-first')).toEqual('');
|
||||
expect(div.attr('i-second')).toEqual('');
|
||||
expect(div.attr('i-second')).toEqual(undefined);
|
||||
expect(div.attr('i-third')).toEqual('');
|
||||
expect(div.attr('i-last')).toEqual('');
|
||||
|
||||
@@ -1127,7 +1127,7 @@ describe('$compile', function() {
|
||||
|
||||
var div = element.find('div');
|
||||
expect(div.attr('i-first')).toEqual('');
|
||||
expect(div.attr('i-second')).toEqual('');
|
||||
expect(div.attr('i-second')).toEqual(undefined);
|
||||
expect(div.attr('i-third')).toEqual('');
|
||||
expect(div.attr('i-last')).toEqual('');
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
describe('ngRepeat', function() {
|
||||
var element, $compile, scope, $exceptionHandler;
|
||||
var element, $compile, scope, $exceptionHandler, $compileProvider;
|
||||
|
||||
beforeEach(module(function(_$compileProvider_) {
|
||||
$compileProvider = _$compileProvider_;
|
||||
}));
|
||||
|
||||
|
||||
beforeEach(module(function($exceptionHandlerProvider) {
|
||||
@@ -448,6 +452,95 @@ describe('ngRepeat', function() {
|
||||
});
|
||||
|
||||
|
||||
describe('nesting in replaced directive templates', function() {
|
||||
|
||||
it('should work when placed on a root element of attr directive with SYNC replaced template',
|
||||
inject(function($templateCache, $compile, $rootScope) {
|
||||
$compileProvider.directive('replaceMeWithRepeater', function() {
|
||||
return {
|
||||
replace: true,
|
||||
template: '<span ng-repeat="i in items">{{log(i)}}</span>'
|
||||
}
|
||||
});
|
||||
element = jqLite('<span replace-me-with-repeater></span>');
|
||||
$compile(element)($rootScope);
|
||||
expect(element.text()).toBe('');
|
||||
var logs = [];
|
||||
$rootScope.log = function(t) { logs.push(t); };
|
||||
|
||||
// This creates one item, but it has no parent so we can't get to it
|
||||
$rootScope.items = [1, 2];
|
||||
$rootScope.$apply();
|
||||
|
||||
// This cleans up to prevent memory leak
|
||||
$rootScope.items = [];
|
||||
$rootScope.$apply();
|
||||
expect(angular.mock.dump(element)).toBe('<!-- ngRepeat: i in items -->');
|
||||
expect(logs).toEqual([1, 2, 1, 2]);
|
||||
}));
|
||||
|
||||
|
||||
iit('should work when placed on a root element of attr directive with ASYNC replaced template',
|
||||
inject(function($templateCache, $compile, $rootScope) {
|
||||
$compileProvider.directive('replaceMeWithRepeater', function() {
|
||||
return {
|
||||
replace: true,
|
||||
templateUrl: 'replace-me-with-repeater.html'
|
||||
}
|
||||
});
|
||||
$templateCache.put('replace-me-with-repeater.html', '<div ng-repeat="i in items">{{log(i)}}</div>');
|
||||
element = jqLite('<span>-</span><span replace-me-with-repeater></span><span>-</span>');
|
||||
$compile(element)($rootScope);
|
||||
expect(element.text()).toBe('--');
|
||||
var logs = [];
|
||||
$rootScope.log = function(t) { logs.push(t); };
|
||||
|
||||
// This creates one item, but it has no parent so we can't get to it
|
||||
$rootScope.items = [1, 2];
|
||||
$rootScope.$apply();
|
||||
|
||||
// This cleans up to prevent memory leak
|
||||
$rootScope.items = [];
|
||||
$rootScope.$apply();
|
||||
expect(sortedHtml(element)).toBe('<span>-</span><!-- ngRepeat: i in items --><span>-</span>');
|
||||
expect(logs).toEqual([1, 2, 1, 2]);
|
||||
}));
|
||||
|
||||
|
||||
it('should work when placed on a root element of element directive with SYNC replaced template',
|
||||
inject(function($templateCache, $compile, $rootScope) {
|
||||
$compileProvider.directive('replaceMeWithRepeater', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
template: '<div ng-repeat="i in [1,2,3]">{{i}}</div>'
|
||||
}
|
||||
});
|
||||
element = $compile('<div><replace-me-with-repeater></replace-me-with-repeater></div>')($rootScope);
|
||||
expect(element.text()).toBe('');
|
||||
$rootScope.$apply();
|
||||
expect(element.text()).toBe('123');
|
||||
}));
|
||||
|
||||
|
||||
it('should work when placed on a root element of element directive with ASYNC replaced template',
|
||||
inject(function($templateCache, $compile, $rootScope) {
|
||||
$compileProvider.directive('replaceMeWithRepeater', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
templateUrl: 'replace-me-with-repeater.html'
|
||||
}
|
||||
});
|
||||
$templateCache.put('replace-me-with-repeater.html', '<div ng-repeat="i in [1,2,3]">{{i}}</div>');
|
||||
element = $compile('<div><replace-me-with-repeater></replace-me-with-repeater></div>')($rootScope);
|
||||
expect(element.text()).toBe('');
|
||||
$rootScope.$apply();
|
||||
expect(element.text()).toBe('123');
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
describe('stability', function() {
|
||||
var a, b, c, d, lis;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user