I have a well-defined model, written this way:
export class Navigation {
line: {
_id: string;
code: string;
name: string;
isVia: boolean;
_operator: {
_id: string;
name: string;
};
via: {
_id: string;
name: string;
}
};
hour: string;
destiny: string;
}
On a certain page I'm starting in a variable before the constructor and I do this:
public navigation: Navigation = new Navigation();
Down in construtor
I'm doing this:
this.navigation.destiny = 'center';
this.navigation.line.isVia = false;
this.navigation.line.via.name = 'Nenhuma via para esta linha';
I can access the properties hour
and destiny
however the properties for example of line does not work. In my console is giving the following error:
ERROR Error: Uncaught (in promise): TypeError: Can not set property 'isVia' of undefined TypeError: Can not set property 'isVia' of undefined
I need to use the model data.
What can be and how to arrange?
TRY
Both of these occur the same error.
SENIOR
I'm developing on ionic 2
basically it works with angular 4
and uses typescript
as language. When I create a page in 'ionic 4' it generates files in ( .html
, .ts
, .scss
, .modeule.ts
) the .ts
file controls my pages, I can easily handle all my html
making requests to the server and changing the screen at runtime easily. For a better development I use the idea of models
to standardize my content both receive and receive when sending, based on this everything I receive / send has the formulation of a model
. The model is a separate file, in case mine is expressed in its total form (ie every file) in my .ts
of my page I am instantiating this my model, saying that my variable navigation
will take the form of my model Navigation
shortly after my constructor having added a value, for as I told ascima use in my html. At this point I am trying the error that I express in this question.
To reproduce the error it is necessary to use a model
"complex", that is to say that it has objects object, it can be observed in mine that I have values in the root ( destiny
, hour
) and a line
object % within this object I have others, I can not access this object from line
and nothing inside it.