1

I am using Angular Version 2.1.0 and writing one of service to load a component dynamically.

I an getting below error, how to resolve it?

Error TS7017 Index signature of object type implicitly has an 'any' type.

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();
        }
    }
}
shazia perween
  • 587
  • 1
  • 8
  • 23
  • It appears `this.appRef['_rootComponents'][0].location` isn't of type `ElementRef` – eko Dec 21 '16 at 04:36

1 Answers1

0

It tells you that when you do this.appRef['_rootComponents'] it does not know what the type of the property is and assumes any by default which is treated as an error according to settings in tsc configuration file. Please read this discussion for more details and possible solutions.

Community
  • 1
  • 1
Alexander Leonov
  • 4,694
  • 1
  • 17
  • 25