TS2453使用componentFactoryResolver

时间:2017-08-07 11:48:05

标签: angular

我遇到了componentFactoryResolver的问题。

const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.getItemMap(this.film.type));

getItemMap (type) {
    switch (type) {
        case 'comedy':
            return ComedyFilmComponent;
        case 'horror':
            return HorrorFilmComponent;
    }
}

在编译时它会抛出下一个错误:

ERROR in ...(45,34): The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'ComedyFilmComponent' is not a valid type argument because it is not a supertype of candidate 'CartoonFilmComponent'.
Property 'isShownDetails' is missing in type 'HorrorFilmComponent'.

我该如何解决,问题是什么?

ComedyFilmConponent:

Component({
  selector: 'comedy-film',
  templateUrl: './comedy-film.component.html',
  styleUrls: ['./comedy-film.component.scss'],
  encapsulation: ViewEncapsulation.None
});
export class ComedyFilmComponent implements OnInit {
    private isShownDetails;

    constructor(@Host() private parent: MainComponent) { }

    ngOnInit() {
        this.isShownDetails = false;
    }
}

HorrorFilmComponent是一样的。那里没有逻辑。

0 个答案:

没有答案