diff --git a/src/directives/init.js b/src/directives/init.js index 5a89ade..13f8667 100644 --- a/src/directives/init.js +++ b/src/directives/init.js @@ -51,6 +51,9 @@ function ($scope, $attrs, $parse, flowFactory) { } }); $parse(name).assign($scope, flow); + $scope.$on('$destroy', function () { + $parse(name).assign($scope); + }); }]) .directive('ngFlowInit', [function() { return { diff --git a/test/init.spec.js b/test/init.spec.js index 86e282d..6372040 100644 --- a/test/init.spec.js +++ b/test/init.spec.js @@ -38,4 +38,17 @@ describe('init', function() { expect($rootScope.obj.flow instanceof Flow).toBeTruthy(); expect($rootScope.obj.flow).toBe(elementScope.obj.flow); }); + + it('should destroy $flow', function() { + $rootScope.obj = {flow:''}; + $rootScope.show = true; + element = $compile('
')($rootScope); + $rootScope.$digest(); + elementScope = element.scope(); + expect($rootScope.obj.flow).toBeDefined(); + expect($rootScope.obj.flow instanceof Flow).toBeTruthy(); + $rootScope.show = false; + $rootScope.$digest(); + expect($rootScope.obj.flow).toBeUndefined(); + }); }); \ No newline at end of file