mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-18 07:50:52 +08:00
fix($compile): reference correct directive name in ctreq error
Previously, ctreq would possibly reference the incorrect directive name, due to relying on a directiveName living outside of the closure which throws the exception, which can change before the call is ever made. This change saves the current value of directiveName as a property of the link function, which prevents this from occurring. Closes #7062 Closes #7067
This commit is contained in:
@@ -3498,6 +3498,27 @@ describe('$compile', function() {
|
||||
expect(element.text()).toBe('Hello');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should throw ctreq with correct directive name, regardless of order', function() {
|
||||
module(function($compileProvider) {
|
||||
$compileProvider.directive('aDir', valueFn({
|
||||
restrict: "E",
|
||||
require: "ngModel",
|
||||
link: noop
|
||||
}));
|
||||
});
|
||||
inject(function($compile, $rootScope) {
|
||||
expect(function() {
|
||||
// a-dir will cause a ctreq error to be thrown. Previously, the error would reference
|
||||
// the last directive in the chain (which in this case would be ngClick), based on
|
||||
// priority and alphabetical ordering. This test verifies that the ordering does not
|
||||
// affect which directive is referenced in the minErr message.
|
||||
element = $compile('<a-dir ng-click="foo=bar"></a-dir>')($rootScope);
|
||||
}).toThrowMinErr('$compile', 'ctreq',
|
||||
"Controller 'ngModel', required by directive 'aDir', can't be found!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user