From 705f4bbf115d2408e33b25f56edbf1f383aabb82 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 2 May 2012 21:08:02 -0700 Subject: fix($compile): attach scope to the directive element when templateUrl and replace=true We forgot to reattach the scope to the replacement element. This affected only directives that had templateUrl and replace:true properties. Reported on the mailing list: https://groups.google.com/forum/?fromgroups#!topic/angular/zwjLr1msS2Y http://jsfiddle.net/lukebayes/g9Sh9/ --- test/ng/compileSpec.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'test/ng') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 74eaec8a..1c4a1d30 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -991,6 +991,33 @@ describe('$compile', function() { } }; }); + $compileProvider.directive('tscope' + uppercase(name), function(log) { + return { + scope: true, + restrict: 'CA', + templateUrl: 'tscope.html', + compile: function() { + return function (scope, element) { + log(scope.$id); + expect(element.data('$scope')).toBe(scope); + }; + } + }; + }); + $compileProvider.directive('trscope' + uppercase(name), function(log) { + return { + scope: true, + replace: true, + restrict: 'CA', + templateUrl: 'trscope.html', + compile: function() { + return function (scope, element) { + log(scope.$id); + expect(element.data('$scope')).toBe(scope); + }; + } + }; + }); $compileProvider.directive('tiscope' + uppercase(name), function(log) { return { scope: {}, @@ -1034,6 +1061,33 @@ describe('$compile', function() { })); + it('should allow creation of new scopes for directives with templates', inject( + function($rootScope, $compile, log, $httpBackend) { + $httpBackend.expect('GET', 'tscope.html').respond('{{name}}; scopeId: {{$id}}'); + element = $compile('