mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-24 13:53:43 +00:00
fix($compile): don't instantiate controllers twice for element transclude directives
This is a fix for regression introduced last week by faf5b980.
Closes #4654
This commit is contained in:
parent
797c99eabe
commit
18ae985c3a
2 changed files with 48 additions and 3 deletions
|
|
@ -1191,9 +1191,13 @@ function $CompileProvider($provide) {
|
||||||
|
|
||||||
childTranscludeFn = compile($template, transcludeFn, terminalPriority,
|
childTranscludeFn = compile($template, transcludeFn, terminalPriority,
|
||||||
replaceDirective && replaceDirective.name, {
|
replaceDirective && replaceDirective.name, {
|
||||||
controllerDirectives: controllerDirectives,
|
// Don't pass in:
|
||||||
newIsolateScopeDirective: newIsolateScopeDirective,
|
// - controllerDirectives - otherwise we'll create duplicates controllers
|
||||||
templateDirective: templateDirective,
|
// - newIsolateScopeDirective or templateDirective - combining templates with
|
||||||
|
// element transclusion doesn't make sense.
|
||||||
|
//
|
||||||
|
// We need only transcludeDirective so that we prevent putting transclusion
|
||||||
|
// on the same element more than once.
|
||||||
transcludeDirective: transcludeDirective
|
transcludeDirective: transcludeDirective
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -3179,6 +3179,47 @@ describe('$compile', function() {
|
||||||
expect(log).toEqual('compile:elementTrans; compile:regularTrans; regular');
|
expect(log).toEqual('compile:elementTrans; compile:regularTrans; regular');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should instantiate high priority controllers only once, but low priority ones each time we transclude',
|
||||||
|
function() {
|
||||||
|
module(function() {
|
||||||
|
directive('elementTrans', function(log) {
|
||||||
|
return {
|
||||||
|
transclude: 'element',
|
||||||
|
priority: 50,
|
||||||
|
controller: function($transclude, $element) {
|
||||||
|
log('controller:elementTrans');
|
||||||
|
$transclude(function(clone) {
|
||||||
|
$element.after(clone);
|
||||||
|
});
|
||||||
|
$transclude(function(clone) {
|
||||||
|
$element.after(clone);
|
||||||
|
});
|
||||||
|
$transclude(function(clone) {
|
||||||
|
$element.after(clone);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
directive('normalDir', function(log) {
|
||||||
|
return {
|
||||||
|
controller: function() {
|
||||||
|
log('controller:normalDir');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
inject(function($compile, $rootScope, log) {
|
||||||
|
element = $compile('<div><div element-trans normal-dir></div></div>')($rootScope);
|
||||||
|
expect(log).toEqual([
|
||||||
|
'controller:elementTrans',
|
||||||
|
'controller:normalDir',
|
||||||
|
'controller:normalDir',
|
||||||
|
'controller:normalDir'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue