获得角度2版本的错误,代码来自RC版本

时间:2016-12-20 08:35:52

标签: angular

我正在使用Angular 2版本" 2.1.0"并写在下面" SpinnerService"。

以下代码来自Angular RC 1,不支持版本" 2.1.0",

这是我所指的plnkr代码,

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();
    }
}
}

我收到以下错误,

  1. 错误TS2305:模块'" C:/ bugFix / WebPackPOC / src / WebPackApp / node_modules / @ angular / core / index"'没有导出的成员' DynamicComponentLoader'。
  2. 错误TS2314:通用类型' ComponentRef'需要1个类型的参数。
  3. 错误TS7017:对象类型的索引签名隐含地有一个' any'类型。
  4. 错误TS2314:通用类型' ComponentRef'需要1个类型的参数。
  5. 请建议使用版本2.1.0进行此更改需要进行哪些更改?谢谢!

0 个答案:

没有答案
相关问题