I have created a starter dictionary for my Angular 6 app...
import { Injectable } from "@angular/core";
@Injectable()
export class Languages {
//template (in English)
public dialect = {
"Vocab": [{
"Pg1": {
"tag1": "my first string",
"tag2": "my second string",
"tag3": "my third string"
}
}, {
"Pg2": {
"tag1": "my fourth string",
"tag2": "my fifth string",
"tag3": "my sixth string"
}
}, {
"Pg3": {
"tag1": "my seventh string",
"tag2": "my eighth string",
"tag3": "my nineth string"
}
}, ]
}
}
When I type this in the calling component...
console.log(this.languages.dialect.Vocab[0].Pg1.ta
...it auto completes the tag I choose for me--in this case I select "tag2". So I know it all works right. When I run the app, the console shows the string "my second string".
All good
However... when I backtrack, and type "Vocab[0].Pg2.ta" it still auto completes for me, but when I choose any value other than Pg1, I get the following error...
ERROR TypeError: "this.languages.dialect.Vocab[0].Pg2 is undefined"
No errors show in the IDE, and the app compiles just fine. What am I doing wrong?