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

Commit b1246bf

Browse files
committed
fix($compile): use createMap() for $$observe listeners when initialized from attr interpolation
1 parent bd6c04a commit b1246bf

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23592359
compile: function() {
23602360
return {
23612361
pre: function attrInterpolatePreLinkFn(scope, element, attr) {
2362-
var $$observers = (attr.$$observers || (attr.$$observers = {}));
2362+
var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
23632363

23642364
if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
23652365
throw $compileMinErr('nodomevents',

test/ng/compileSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -3274,6 +3274,22 @@ describe('$compile', function() {
32743274
});
32753275
});
32763276

3277+
it('should be able to interpolate attribute names which are present in Object.prototype', function() {
3278+
var attrs;
3279+
module(function() {
3280+
directive('attrExposer', valueFn({
3281+
link: function($scope, $element, $attrs) {
3282+
attrs = $attrs;
3283+
}
3284+
}));
3285+
});
3286+
inject(function($compile, $rootScope) {
3287+
$compile('<div attr-exposer to-string="{{1 + 1}}">')($rootScope);
3288+
$rootScope.$apply();
3289+
expect(attrs.toString).toBe('2');
3290+
});
3291+
});
3292+
32773293

32783294
it('should not initialize scope value if optional expression binding is not passed', inject(function($compile) {
32793295
compile('<div my-component></div>');

0 commit comments

Comments
 (0)