I have the following scenario. I have a list in a webservice, but when I do a return to pass the value to my component it simply does not bind because it is time consuming, and even when it comes back I call the WS again it does not update the data. Here's how I'm trying to implement it. I've made this example over without putting the imports just to put here and expose the menu that 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;
});
}
}