2016-12-21 8 views
0

私はAngular Version 2.1.0を使用しており、コンポーネントを動的にロードするサービスの1つを記述しています。エラーを取得していますオブジェクト型のインデックスシグネチャが暗黙的に 'any'型を持っています

私は以下のエラーが発生しました。どのように解決するのですか?

エラーTS7017オブジェクトタイプのインデックスに暗黙的に「any」タイプがあります。

import { Injectable, ComponentFactoryResolver, ApplicationRef, ElementRef, ViewContainerRef } from '@angular/core'; 
 

 
import { SpinnerComponent } from '../components/blockui/blockui.component'; 
 

 

 
@Injectable() 
 
export class SpinnerService { 
 
    spinnerComp: ViewContainerRef; 
 
    constructor(private componentLoader: ComponentFactoryResolver, private appRef: ApplicationRef) { } 
 

 
    public start() { 
 
     //error in this line? 
 
     let elementRef: ElementRef = this.appRef['_rootComponents'][0].location; 
 

 
     return this.startInside(elementRef, null); 
 
    } 
 

 
    public startInside(elementRef: ElementRef, anchorName: string) { 
 

 
     let spinnerRef = (!anchorName) ? 
 
      this.componentLoader.resolveComponentFactory.call(SpinnerComponent, elementRef) : 
 
      this.componentLoader.resolveComponentFactory.call(SpinnerComponent, elementRef, anchorName); 
 

 
     spinnerRef.then((compRef: ViewContainerRef) => { 
 
      this.spinnerComp = compRef; 
 
     }); 
 
    } 
 

 
    public stop() { 
 
     if (this.spinnerComp) { 
 
      this.spinnerComp.detach(); 
 
     } 
 
    } 
 
}

+0

'this.appRef ['_ rootComponents'] [0] .location'はタイプ 'ElementRef'ではありません – echonax

答えて

0

それはあなたがthis.appRef['_rootComponents']を行う際には、プロパティのタイプが何であるかを知らないことを示していますし、TSCの構成での設定に従って、エラーとして扱われ、デフォルトでanyを前提としていファイル。詳細および可能な解決策については、this discussionをお読みください。

関連する問題