File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ var componentAsDirective = ['$parse', function($parse) {
58
58
// gets the controller of the current element (see jqLiteController for details)
59
59
var controller = iElement . data ( '$' + controllerName + 'Controller' ) ;
60
60
setter ( scope , controller ) ;
61
+
62
+ // when the element is removed, remove it from the scope assignment (nullify it)
63
+ iElement . on ( '$destroy' , function ( ) {
64
+ setter ( scope , null ) ;
65
+ } ) ;
61
66
} ;
62
67
}
63
68
} ;
Original file line number Diff line number Diff line change @@ -54,6 +54,16 @@ describe('as', function() {
54
54
expect ( $rootScope . $ctrl . myComponent2 ) . toBe ( myComponentController ) ;
55
55
} ) ;
56
56
57
+ it ( 'should nullify the variable once the component is destroyed' , function ( ) {
58
+ $rootScope . $ctrl = { } ;
59
+ $compile ( '<div ng-if="!nullified"><my-component as="$ctrl.myComponent"></my-component></div>' ) ( $rootScope ) ;
60
+ $rootScope . $apply ( 'nullified = false' ) ;
61
+ expect ( $rootScope . $ctrl . myComponent ) . toBe ( myComponentController ) ;
62
+
63
+ $rootScope . $apply ( 'nullified = true' ) ;
64
+ expect ( $rootScope . $ctrl . myComponent ) . toBe ( null ) ;
65
+ } ) ;
66
+
57
67
} ) ;
58
68
59
69
it ( 'should be compatible with directives on entities with controller' , function ( ) {
You can’t perform that action at this time.
0 commit comments