Data typing

0

Alright?

Putting into practice what I learned in angular / ionic, I came across some doubts:

1- I made an ion-select with list of states coming from the firebase. When I typed the States model, I'm in doubt if in the model I do export interface or export class . I saw that I can do both ways, but what difference does it make and what does it mean?

2- When I returned the list of firebase states, I used this.af.database.ref ("/ states") and not this.af.database.list ("/ states") as it is in the course. I was doubtful at the time of return of the service. Because the syntax is different and it was not clear to me what kind and how this return is. See:

cadastro.ts

ionViewDidLoad() {
    this.estados = this.estadosService.listar();
}

cadastro.service.ts

listar():any{ // este any deveria ser do tipo Estados, correto?
    return this.af.database.ref('/estados')
        .once('value')
        .then( (resposta) => {
            return resposta.val();
        })
        .catch( (erro) => {
            console.log(erro);
        })
} 

If you can not explain well and want to see the whole code to better understand my doubts, follow in github:

Github

    
asked by anonymous 21.09.2017 / 14:51

1 answer

0

The return of the List () method of your service registration is of type "any". That is, it is dynamic. This type of method is interesting to use when you need to describe the type of variables you do not know when writing an application. And those values can come from dynamic content.

See more at:

  

link

In the case of the List () method, callback is not typed anywhere. It would be necessary for you to create a model and map the result to that type before returning to the component. See more at:

  

link

    
01.11.2017 / 01:09