4
I have the following scenario.
I have a list in one webservice, but when I expect a return to pass the value to my component, it just doesn’t do the Binding because it takes time, and even when it does, in case I call the WS again, it does not update the data.
Below is code of how I am trying to implement. I did this example on top without putting the imports
, just to put here and expose the way I’m trying to implement.
@Component({
template:'<div *ngFor="let dados of lista">{{dados.nome}}<br/></div>',
selector: 'meu-component'
})
MeuComponent {
private _vaiPraView: any;
@Input() testes: any;
ngOnInit() {
this.trataDados();
}
trataDados () {
this._vaiPraView = [];
let idx = 0;
for(let teste of this.testes) {
teste.realvector = idx;
idx++;
this._vaiPraView.push(teste);
}
}
}
//html... com binding (não rola...)
@Component({
template:'<meu-component [testes]="lista"></meu-component>',
directives: [MeuComponent]
})
export class TestePage {
private lista: any;
constructor() {
}
ngOnInit () {
//Um evento demorado.. formato de data exemplo: [{nome: 'oi'},{nome: 'tudobem'},{nome: 'contigo'}]
AlgumaCoisa.then(data => {
this.lista = data;
});
}
}
//html... sem binding rola porém quero que fique do jeito acima e detecte a alteração.
@Component({
template:'<meu-component [testes]="[{nome: 'oi'},{nome: 'tudobem'},{nome: 'contigo'}]"></meu-component>',
directives: [MeuComponent]
})
export class TestePage {
private lista: any;
constructor() {
}
ngOnInit () {
//Um evento demorado.. formato de data exemplo: [{nome: 'oi'},{nome: 'tudobem'},{nome: 'contigo'}]
AlgumaCoisa.then(data => {
this.lista = data;
});
}
}
In the first part there
MeuComponent { ...
you didn’t use theexport class
, could the problem be there?– wdarking
I do not believe that was it @wdarking ... Wow how long this question rs... It was starting at angular yet.
– Hiago Souza