Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($compile): prevent double attr interpolation w/ templateUrl
Browse files Browse the repository at this point in the history
This fixes the issue that caused two attr interpolation observers
to be registered for the same attribute as a result of isolate
scope definition with attr (@) property for this attribute.

Duplicate observers would then fight with each other updating the
model.

The issue occured only when this directive was used in a repeater
because that's when we clone the template node which caused the
two observers to point to two different sets of $attr instances.

Closes #1166, #836
  • Loading branch information
IgorMinar committed Oct 30, 2012
1 parent bca1604 commit fc115bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ function $CompileProvider($provide) {
origAsyncDirective = directives.shift(),
// The fact that we have to copy and patch the directive seems wrong!
derivedSyncDirective = extend({}, origAsyncDirective, {
controller: null, templateUrl: null, transclude: null
controller: null, templateUrl: null, transclude: null, scope: null
});

$compileNode.html('');
Expand Down
33 changes: 33 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,39 @@ describe('$compile', function() {
expect($exceptionHandler.errors).toEqual([]);
});
});


it('should resume delayed compilation without duplicates when in a repeater', function() {
// this is a test for a regression
// scope creation, isolate watcher setup, controller instantiation, etc should happen
// only once even if we are dealing with delayed compilation of a node due to templateUrl
// and the template node is in a repeater

var controllerSpy = jasmine.createSpy('controller');

module(function($compileProvider) {
$compileProvider.directive('delayed', valueFn({
controller: controllerSpy,
templateUrl: 'delayed.html',
scope: {
title: '@'
}
}));
});

inject(function($templateCache, $compile, $rootScope) {
$rootScope.coolTitle = 'boom!';
$templateCache.put('delayed.html', '<div>{{title}}</div>');
element = $compile(
'<div><div ng-repeat="i in [1,2]"><div delayed title="{{coolTitle + i}}"></div>|</div></div>'
)($rootScope);

$rootScope.$apply();

expect(controllerSpy.callCount).toBe(2);
expect(element.text()).toBe('boom!1|boom!2|');
});
});
});


Expand Down

0 comments on commit fc115bf

Please sign in to comment.