1

I am using Angular 2 version "2.1.0" and writing below "SpinnerService".

This below code is from Angular RC 1 and not supported in version "2.1.0",

this is plnkr code I m referring,

http://plnkr.co/edit/Y2ocRpbi2ORjbULrguDg?p=info

import { Injectable, DynamicComponentLoader, ApplicationRef, ElementRef, ComponentRef } from '@angular/core';

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

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

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

    return this.startInside(elementRef, null);
}

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

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

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

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

I am getting below error,

  1. error TS2305: Module '"C:/bugFix/WebPackPOC/src/WebPackApp/node_modules/@angular/core/index"' has no exported member 'DynamicComponentLoader'.
  2. error TS2314: Generic type 'ComponentRef' requires 1 type argument(s).
  3. error TS7017: Index signature of object type implicitly has an 'any' type.
  4. error TS2314: Generic type 'ComponentRef' requires 1 type argument(s).

Please suggest what change need to make to work this with version 2.1.0? Thanks!

shazia perween
  • 587
  • 1
  • 8
  • 23
  • `DynamicComponentLoader` is deprecated since rc-4. See http://stackoverflow.com/questions/38332249/angular-2-rc4-dynamiccomponentloader-deprecated – Jordi Nebot Dec 20 '16 at 08:49
  • `DynamicComponentLoader` is deprecated, you have to use `ComponentResolver` or `ViewContainerRef` instead, check [this commit](https://github.com/angular/angular/commit/5297c9d9ccc6f8831d1656915e3d78e767022517) for more details. – LoïcR Dec 20 '16 at 08:51
  • thanks, after changing it to "ViewContainerRef ", I am getting below error, "error TS2314: Generic type 'ComponentRef' requires 1 type argument(s)." – shazia perween Dec 20 '16 at 08:57
  • also, error TS2339: Property 'loadNextToLocation' does not exist on type 'ViewContainerRef'. – shazia perween Dec 20 '16 at 08:57
  • component resolver is also deprecated – shazia perween Dec 20 '16 at 09:00
  • this is the plnkrcode I am referring, http://plnkr.co/edit/Y2ocRpbi2ORjbULrguDg?p=info – shazia perween Dec 20 '16 at 09:04

0 Answers0