Skip to content

Commit 8d8c67e

Browse files
committed
fix: destory attribute then element is removed
1 parent dcfd7cb commit 8d8c67e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/directives/init.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ function ($scope, $attrs, $parse, flowFactory) {
5151
}
5252
});
5353
$parse(name).assign($scope, flow);
54+
$scope.$on('$destroy', function () {
55+
$parse(name).assign($scope);
56+
});
5457
}])
5558
.directive('ngFlowInit', [function() {
5659
return {

test/init.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,17 @@ describe('init', function() {
3838
expect($rootScope.obj.flow instanceof Flow).toBeTruthy();
3939
expect($rootScope.obj.flow).toBe(elementScope.obj.flow);
4040
});
41+
42+
it('should destroy $flow', function() {
43+
$rootScope.obj = {flow:''};
44+
$rootScope.show = true;
45+
element = $compile('<div ng-flow-init="{}" ng-if="show" ng-flow-name="obj.flow"></div>')($rootScope);
46+
$rootScope.$digest();
47+
elementScope = element.scope();
48+
expect($rootScope.obj.flow).toBeDefined();
49+
expect($rootScope.obj.flow instanceof Flow).toBeTruthy();
50+
$rootScope.show = false;
51+
$rootScope.$digest();
52+
expect($rootScope.obj.flow).toBeUndefined();
53+
});
4154
});

0 commit comments

Comments
 (0)