From a277e97dd79b53fdbc9e0283a7ebbaa8caed94c4 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Sat, 3 Dec 2016 23:32:47 +0300 Subject: [PATCH] fix(core): ViewContainerRef.indexOf doesn't throw error when empty (#13220) PR Close #13220 --- modules/@angular/core/src/linker/view_container_ref.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/@angular/core/src/linker/view_container_ref.ts b/modules/@angular/core/src/linker/view_container_ref.ts index d21ff0f669..947f8a1dc1 100644 --- a/modules/@angular/core/src/linker/view_container_ref.ts +++ b/modules/@angular/core/src/linker/view_container_ref.ts @@ -186,7 +186,8 @@ export class ViewContainerRef_ implements ViewContainerRef { } indexOf(viewRef: ViewRef): number { - return this._element.nestedViews.indexOf((>viewRef).internalView); + return this.length ? this._element.nestedViews.indexOf((>viewRef).internalView) : + -1; } /** @internal */ @@ -213,7 +214,7 @@ export class ViewContainerRef_ implements ViewContainerRef { return wtfLeave(s, view.ref); } - clear() { + clear(): void { for (let i = this.length - 1; i >= 0; i--) { this.remove(i); }