fix($compile): always use the DDO as this in pre-/post-linking functions
Closes #9306
This commit is contained in:
committed by
Georgios Kalpakas
parent
921f80e1ea
commit
7d0fe19734
+2
-2
@@ -2342,9 +2342,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
try {
|
||||
linkFn = directive.compile($compileNode, templateAttrs, childTranscludeFn);
|
||||
if (isFunction(linkFn)) {
|
||||
addLinkFns(null, linkFn, attrStart, attrEnd);
|
||||
addLinkFns(null, bind(directive, linkFn), attrStart, attrEnd);
|
||||
} else if (linkFn) {
|
||||
addLinkFns(linkFn.pre, linkFn.post, attrStart, attrEnd);
|
||||
addLinkFns(bind(directive, linkFn.pre), bind(directive, linkFn.post), attrStart, attrEnd);
|
||||
}
|
||||
} catch (e) {
|
||||
$exceptionHandler(e, startingTag($compileNode));
|
||||
|
||||
@@ -225,6 +225,96 @@ describe('$compile', function() {
|
||||
});
|
||||
inject(function($compile) {});
|
||||
});
|
||||
|
||||
it('should preserve context within declaration', function() {
|
||||
module(function() {
|
||||
directive('ff', function(log) {
|
||||
var declaration = {
|
||||
restrict: 'E',
|
||||
template: function(){
|
||||
log('ff template: ' + (this === declaration));
|
||||
},
|
||||
compile: function(){
|
||||
log('ff compile: ' + (this === declaration));
|
||||
return function(){
|
||||
log('ff post: ' + (this === declaration));
|
||||
};
|
||||
}
|
||||
};
|
||||
return declaration;
|
||||
});
|
||||
|
||||
directive('fff', function(log) {
|
||||
var declaration = {
|
||||
restrict: 'E',
|
||||
link: {
|
||||
pre: function(){
|
||||
log('fff pre: ' + (this === declaration));
|
||||
},
|
||||
post: function(){
|
||||
log('fff post: ' + (this === declaration));
|
||||
}
|
||||
}
|
||||
};
|
||||
return declaration;
|
||||
});
|
||||
|
||||
directive('ffff', function(log) {
|
||||
var declaration = {
|
||||
restrict: 'E',
|
||||
compile: function(){
|
||||
return {
|
||||
pre: function(){
|
||||
log('ffff pre: ' + (this === declaration));
|
||||
},
|
||||
post: function(){
|
||||
log('ffff post: ' + (this === declaration));
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
return declaration;
|
||||
});
|
||||
|
||||
directive('fffff', function(log) {
|
||||
var declaration = {
|
||||
restrict: 'E',
|
||||
templateUrl: function(){
|
||||
log('fffff: ' + (this === declaration));
|
||||
}
|
||||
};
|
||||
return declaration;
|
||||
});
|
||||
|
||||
directive('ffffff', function(log) {
|
||||
var declaration = {
|
||||
restrict: 'E',
|
||||
link: function(){
|
||||
log('ffffff: ' + (this === declaration));
|
||||
}
|
||||
};
|
||||
return declaration;
|
||||
});
|
||||
});
|
||||
inject(function($compile, $rootScope, log) {
|
||||
$compile('<ff></ff>')($rootScope);
|
||||
$compile('<fff></fff>')($rootScope);
|
||||
$compile('<ffff></ffff>')($rootScope);
|
||||
$compile('<fffff></fffff>')($rootScope);
|
||||
$compile('<ffffff></ffffff>')($rootScope);
|
||||
expect(log).toEqual(
|
||||
'ff template: true; '+
|
||||
'ff compile: true; '+
|
||||
'ff post: true; '+
|
||||
'fff pre: true; '+
|
||||
'fff post: true; '+
|
||||
'ffff pre: true; '+
|
||||
'ffff post: true; '+
|
||||
'fffff: true; '+
|
||||
'ffffff: true'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user