This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +27
-11
lines changed
2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 60
60
}
61
61
62
62
/*
63
- The transition styles can also be placed on the CSS base class above
63
+ The transition styles can also be placed on the CSS base class above
64
64
*/
65
65
.animate-if.ng-enter, .animate-if.ng-leave {
66
66
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
@@ -92,16 +92,16 @@ var ngIfDirective = ['$animate', function($animate) {
92
92
$scope . $watch ( $attr . ngIf , function ngIfWatchAction ( value ) {
93
93
94
94
if ( toBoolean ( value ) ) {
95
-
96
- childScope = $scope . $new ( ) ;
97
- transclude ( childScope , function ( clone ) {
98
- block = {
99
- startNode : clone [ 0 ] ,
100
- endNode : clone [ clone . length ++ ] = document . createComment ( ' end ngIf: ' + $attr . ngIf + ' ' )
101
- } ;
102
- $animate . enter ( clone , $element . parent ( ) , $element ) ;
103
- } ) ;
104
-
95
+ if ( ! childScope ) {
96
+ childScope = $scope . $new ( ) ;
97
+ transclude ( childScope , function ( clone ) {
98
+ block = {
99
+ startNode : clone [ 0 ] ,
100
+ endNode : clone [ clone . length ++ ] = document . createComment ( ' end ngIf: ' + $attr . ngIf + ' ' )
101
+ } ;
102
+ $animate . enter ( clone , $element . parent ( ) , $element ) ;
103
+ } ) ;
104
+ }
105
105
} else {
106
106
107
107
if ( childScope ) {
Original file line number Diff line number Diff line change @@ -28,6 +28,22 @@ describe('ngIf', function () {
28
28
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
29
29
} ) ;
30
30
31
+ it ( 'should not add the element twice if the condition goes from true to true' , function ( ) {
32
+ $scope . hello = 'true1' ;
33
+ makeIf ( 'hello' ) ;
34
+ expect ( element . children ( ) . length ) . toBe ( 1 ) ;
35
+ $scope . $apply ( 'hello = "true2"' ) ;
36
+ expect ( element . children ( ) . length ) . toBe ( 1 ) ;
37
+ } ) ;
38
+
39
+ it ( 'should not recreate the element if the condition goes from true to true' , function ( ) {
40
+ $scope . hello = 'true1' ;
41
+ makeIf ( 'hello' ) ;
42
+ element . children ( ) . data ( 'flag' , true ) ;
43
+ $scope . $apply ( 'hello = "true2"' ) ;
44
+ expect ( element . children ( ) . data ( 'flag' ) ) . toBe ( true ) ;
45
+ } ) ;
46
+
31
47
it ( 'should create then remove the element if condition changes' , function ( ) {
32
48
$scope . hello = true ;
33
49
makeIf ( 'hello' ) ;
You can’t perform that action at this time.
0 commit comments