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

Commit 57705c7

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

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23552355
compile: function() {
23562356
return {
23572357
pre: function attrInterpolatePreLinkFn(scope, element, attr) {
2358-
var $$observers = (attr.$$observers || (attr.$$observers = {}));
2358+
var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
23592359

23602360
if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
23612361
throw $compileMinErr('nodomevents',

test/ng/compileSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,23 @@ describe('$compile', function() {
32183218
});
32193219
});
32203220

3221+
it('should be able to interpolate attribute names which are present in Object.prototype', function() {
3222+
var attrs;
3223+
module(function() {
3224+
directive('attrExposer', valueFn({
3225+
link: function($scope, $element, $attrs) {
3226+
attrs = $attrs;
3227+
}
3228+
}));
3229+
});
3230+
inject(function($compile, $rootScope) {
3231+
$compile('<div attr-exposer to-string="{{1 + 1}}" has-own-property="{{1 + 1}}">')($rootScope);
3232+
$rootScope.$apply();
3233+
expect(attrs.toString).toBe('2');
3234+
expect(attrs.hasOwnProperty).toBe('2');
3235+
});
3236+
});
3237+
32213238

32223239
describe('bind-once', function() {
32233240

0 commit comments

Comments
 (0)