2016-04-05 20 views
1

Dinamik Bileşen Yükleyiciyi kullanıyorum ve tüm veriler bileşen başlatma işleminde başlatılmışsa iyi çalışıyor. Bu kodu kullanıyorum:Angular 2 yeni verileri dinamik olarak yüklenen Dinamik Bileşen Yüklüyor

this.dcl.loadAsRoot(SomeComponent, "#somediv", this.injector).then((cmp)=>{ 

    // @Input() 
    cmp.instance.someinput = this.someinput; 

    // @Output() 
    cmp.instance.someoutput.subscribe(res => { this.consoleLog(res) }) 

    // Trigger change detection 
    cmp.location.internalElement.parentView.changeDetector.ref.detectChanges(); 

    // return data 
    return cmp 

}) 
Şimdi yeni bir değer beslemek istiyorum

için "someinput" değişkeni, bu mümkün yoksa yine tüm bileşeni yeniden başlatmak gerekiyor ?!

+0

başvurusunu tutun. LoadNextToLocation veya loadIntoLocation'ı kullanın. –

cevap

1

Sadece Sen loadAsRoot kullanmak gerekmiyor bileşeni

compRef:ComponentRef; 

someFunc() { 
    this.dcl.loadAsRoot(SomeComponent, "#somediv", this.injector).then((cmp)=>{ 
    this.compRef = cmp; 
    ... 
    } 
} 

someOtherFunc() { 
    this.compRef.someInput = 'someotherValue'; 
    this.compRef.location.internalElement.parentView.changeDetector 
     .ref.detectChange‌​s(); 
} 
+1

İyi, sadece şunu unutmuştunuz: this.compRef.location.internalElement.parentView.changeDetector.ref.detectChanges(); – Teddy

+0

Doğru, ipucu için teşekkürler. –

İlgili konular