Skip to content

Commit 1b3369a

Browse files
committed
Merge pull request #2 from bolasblack/master
fix(Memory Leak): clean tinyInstance after $destroy event
2 parents 8e250b8 + d51ef1b commit 1b3369a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/tinymce.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ angular.module('ui.tinymce', [])
1717
scope.$apply();
1818
}
1919
};
20+
2021
// generate an ID if not present
2122
if (!attrs.id) {
2223
attrs.$set('id', 'uiTinymce' + generatedIds++);
@@ -27,6 +28,7 @@ angular.module('ui.tinymce', [])
2728
} else {
2829
expression = {};
2930
}
31+
3032
options = {
3133
// Update model when calling setContent (such as from the source editor popup)
3234
setup: function (ed) {
@@ -65,7 +67,6 @@ angular.module('ui.tinymce', [])
6567
tinymce.init(options);
6668
});
6769

68-
6970
ngModel.$render = function() {
7071
if (!tinyInstance) {
7172
tinyInstance = tinymce.get(attrs.id);
@@ -74,6 +75,14 @@ angular.module('ui.tinymce', [])
7475
tinyInstance.setContent(ngModel.$viewValue || '');
7576
}
7677
};
78+
79+
scope.$on('$destroy', function() {
80+
if (!tinyInstance) { tinyInstance = tinymce.get(attrs.id); }
81+
if (tinyInstance) {
82+
tinyInstance.remove();
83+
tinyInstance = null;
84+
}
85+
});
7786
}
7887
};
7988
}]);

0 commit comments

Comments
 (0)