fix(core): forbid destroyed views to be inserted or moved in VC (#18568)

Fixes #17780
This commit is contained in:
Marc Laval
2017-08-09 23:11:51 +02:00
committed by Victor Berchet
parent 1e1833198d
commit e54bd59f22
2 changed files with 181 additions and 129 deletions

View File

@ -187,6 +187,9 @@ class ViewContainerRef_ implements ViewContainerData {
}
insert(viewRef: ViewRef, index?: number): ViewRef {
if (viewRef.destroyed) {
throw new Error('Cannot insert a destroyed View in a ViewContainer!');
}
const viewRef_ = <ViewRef_>viewRef;
const viewData = viewRef_._view;
attachEmbeddedView(this._view, this._data, index, viewData);
@ -195,6 +198,9 @@ class ViewContainerRef_ implements ViewContainerData {
}
move(viewRef: ViewRef_, currentIndex: number): ViewRef {
if (viewRef.destroyed) {
throw new Error('Cannot move a destroyed View in a ViewContainer!');
}
const previousIndex = this._embeddedViews.indexOf(viewRef._view);
moveEmbeddedView(this._data, previousIndex, currentIndex);
return viewRef;