File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6060 }
6161
6262 /*
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
6464 */
6565 .animate-if.ng-enter, .animate-if.ng-leave {
6666 -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
@@ -92,16 +92,16 @@ var ngIfDirective = ['$animate', function($animate) {
9292 $scope . $watch ( $attr . ngIf , function ngIfWatchAction ( value ) {
9393
9494 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+ }
105105 } else {
106106
107107 if ( childScope ) {
Original file line number Diff line number Diff line change @@ -28,6 +28,22 @@ describe('ngIf', function () {
2828 expect ( element . children ( ) . length ) . toBe ( 1 ) ;
2929 } ) ;
3030
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+
3147 it ( 'should create then remove the element if condition changes' , function ( ) {
3248 $scope . hello = true ;
3349 makeIf ( 'hello' ) ;
You can’t perform that action at this time.
0 commit comments