2016-07-01 26 views
6

Impossibile rimuovere i componenti dinamici in ionic-2. Si dice eccezione mentre compila dattiloscrittoIl tipo generico 'ComponentRef <C>' richiede 1 tipo argomento (i)

“Generic type 'ComponentRef' requires 1 type argument(s)”.

Inoltre, lo stesso codice funziona mentre si utilizza senza utilizzare ionic2. Apprezzo molto il tuo aiuto. Grazie in anticipo.

class DynamicCmp { 
    _ref: ComponentRef; 
    _idx: number; 
    constructor(private resolver: ComponentResolver, private location: ViewContainerRef) { } 
    remove() { 
    this._ref.destroy(); 
    } 
    add1() { 
    this.resolver.resolveComponent(DynamicCmp).then((factory: ComponentFactory<any>) => { 
     let ref = this.location.createComponent(factory, 0); 
     ref.instance._ref = ref; 
     ref.instance._idx = this._idx++; 
    }); 
    } 
} 

Exception: TypeScript error: ....../home/home.ts(9,11): Erro r TS2314: Generic type 'ComponentRef' requires 1 type argument(s).

risposta

19

ComponentRef è un tipo generico. Basta cambiare il codice come segue:

class DynamicCmp { 
    _ref: ComponentRef<any>; <== add <any> 

Spero che ti aiuti!

+0

o 'DynamicComp' –

+0

Grazie mille. Sta lavorando adesso. – user2932411

Problemi correlati