Skip to content

Commit

Permalink
fix: destory attribute then element is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
AidasK committed Dec 4, 2013
1 parent dcfd7cb commit 8d8c67e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/directives/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions test/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div ng-flow-init="{}" ng-if="show" ng-flow-name="obj.flow"></div>')($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();
});
});

0 comments on commit 8d8c67e

Please sign in to comment.