Non-Angular Class 2

0

This is my angle class 2

export class LinhaModel {
    _id: string;

    Cidade: {
        id: string;
        CidadeNome: string;
    }

    Operador: {
        id: string,
        OperadorNome: string,
    }

    DiaOperacional: {
        id: string,
        DiaOperacionalNome: string,
    }

    CategoriaLinha: {
        id: string,
        CategoriaLinhaNome: string,
    }

    Acessibilidade: boolean

    Tarifa: number

    NomeLinha: string

    CodigoLinha: string

    ViagemA: {
        Origem: string

        Destino: string

        Horarios: any[]

        Vias: [
            {
                ViaNome: string
                ViaHorarios: any[]
            }
        ]
    }


    ViagemB: {
        Origem: string

        Destino: string

        Horarios: any

        Vias: [
            {
                ViaNome: string
                ViaHorarios: any
            }
        ]
    }
}

I'm instantiating my model so

private model: LineModel = new LineModel ();

And when I try to access my property with this.model.Travel.Annex is not accepted! Anyone know how to do this?

    
asked by anonymous 04.03.2017 / 15:36

1 answer

1

The problem is that the TravelA property is not ready to use (TripA = undefined) because no instance has been defined in it. Before using it, you need to assign an object that follows the established contract / format, that is, an object that has the members: Source, String, Arrays, Arrays X).

The solution, not to receive undefined errors, would be to create a constructor in the LineModel class to initialize the TravelA property. For example:

export class LinhaModel {

    constructor()
    {
        this.ViagemA = {};
    }

   ViagemA: {
    Origem: string

    Destino: string

    Horarios: any[]

    Vias: [
        {
            ViaNome: string
            ViaHorarios: any[]
        }
    ]
}


}
    
27.06.2017 / 01:56