This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
function classDirective ( name , selector ) {
4
+ var staticMapClassRegEx = / ^ \s * \{ / ;
4
5
name = 'ngClass' + name ;
5
6
return [ '$animate' , function ( $animate ) {
6
7
return {
7
8
restrict : 'AC' ,
8
9
link : function ( scope , element , attr ) {
9
10
var oldVal ;
10
11
11
- scope . $watch ( attr [ name ] , ngClassWatchAction , true ) ;
12
+ // shortcut: if it is clearly a map of classes do not copy values, they are supposed to be boolean (truly/falsy)
13
+ scope [ staticMapClassRegEx . test ( attr [ name ] ) ? '$watchCollection' : '$watch' ] ( attr [ name ] , ngClassWatchAction , true ) ;
12
14
13
15
attr . $observe ( 'class' , function ( value ) {
14
16
ngClassWatchAction ( scope . $eval ( attr [ name ] ) ) ;
Original file line number Diff line number Diff line change @@ -409,6 +409,15 @@ describe('ngClass', function() {
409
409
expect ( e2 . hasClass ( 'even' ) ) . toBeTruthy ( ) ;
410
410
expect ( e2 . hasClass ( 'odd' ) ) . toBeFalsy ( ) ;
411
411
} ) ) ;
412
+
413
+ it ( 'should not copy large objects via hard map of classes' , inject ( function ( $rootScope , $compile ) {
414
+ element = $compile ( '<div ng-class="{foo: verylargeobject}"></div>' ) ( $rootScope ) ;
415
+ $rootScope . verylargeobject = { very : 'largeobject' } ;
416
+ $rootScope . $digest ( ) ;
417
+
418
+ expect ( $rootScope . $$watchers [ 0 ] . last ) . toEqual ( jasmine . any ( Number ) ) ;
419
+ } ) ) ;
420
+
412
421
} ) ;
413
422
414
423
describe ( 'ngClass animations' , function ( ) {
You can’t perform that action at this time.
0 commit comments