fix(ivy): throw a descriptive error when trying to insert / move destroyed view (#27289)
PR Close #27289
This commit is contained in:
parent
d0e8020506
commit
0487fbe236
|
@ -265,6 +265,7 @@ export class ComponentRef<T> extends viewEngine_ComponentRef<T> {
|
||||||
ngDevMode && assertDefined(this.destroyCbs, 'NgModule already destroyed');
|
ngDevMode && assertDefined(this.destroyCbs, 'NgModule already destroyed');
|
||||||
this.destroyCbs !.forEach(fn => fn());
|
this.destroyCbs !.forEach(fn => fn());
|
||||||
this.destroyCbs = null;
|
this.destroyCbs = null;
|
||||||
|
this.hostView.destroy();
|
||||||
}
|
}
|
||||||
onDestroy(callback: () => void): void {
|
onDestroy(callback: () => void): void {
|
||||||
ngDevMode && assertDefined(this.destroyCbs, 'NgModule already destroyed');
|
ngDevMode && assertDefined(this.destroyCbs, 'NgModule already destroyed');
|
||||||
|
|
|
@ -265,6 +265,9 @@ export function createContainerRef(
|
||||||
}
|
}
|
||||||
|
|
||||||
move(viewRef: viewEngine_ViewRef, newIndex: number): viewEngine_ViewRef {
|
move(viewRef: viewEngine_ViewRef, newIndex: number): viewEngine_ViewRef {
|
||||||
|
if (viewRef.destroyed) {
|
||||||
|
throw new Error('Cannot move a destroyed View in a ViewContainer!');
|
||||||
|
}
|
||||||
const index = this.indexOf(viewRef);
|
const index = this.indexOf(viewRef);
|
||||||
this.detach(index);
|
this.detach(index);
|
||||||
this.insert(viewRef, this._adjustIndex(newIndex));
|
this.insert(viewRef, this._adjustIndex(newIndex));
|
||||||
|
|
|
@ -995,7 +995,8 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
expect(dir.receivedArgs).toEqual(['one', undefined]);
|
expect(dir.receivedArgs).toEqual(['one', undefined]);
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy('unknown') && it('should not allow pipes in hostListeners', () => {
|
fixmeIvy('FW-742: Pipes in host listeners should throw a descriptive error') &&
|
||||||
|
it('should not allow pipes in hostListeners', () => {
|
||||||
@Directive({selector: '[host-listener]', host: {'(click)': 'doIt() | somePipe'}})
|
@Directive({selector: '[host-listener]', host: {'(click)': 'doIt() | somePipe'}})
|
||||||
class DirectiveWithHostListener {
|
class DirectiveWithHostListener {
|
||||||
}
|
}
|
||||||
|
@ -1238,7 +1239,6 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.insert', () => {
|
describe('.insert', () => {
|
||||||
fixmeIvy('unknown') &&
|
|
||||||
it('should throw with destroyed views', async(() => {
|
it('should throw with destroyed views', async(() => {
|
||||||
const fixture = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]})
|
const fixture = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]})
|
||||||
.createComponent(MyComp);
|
.createComponent(MyComp);
|
||||||
|
@ -1255,7 +1255,6 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.move', () => {
|
describe('.move', () => {
|
||||||
fixmeIvy('unknown') &&
|
|
||||||
it('should throw with destroyed views', async(() => {
|
it('should throw with destroyed views', async(() => {
|
||||||
const fixture = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]})
|
const fixture = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]})
|
||||||
.createComponent(MyComp);
|
.createComponent(MyComp);
|
||||||
|
|
Loading…
Reference in New Issue