Whenever I try to declare or initialize data members in a class, the following methods never seem to work:
var view: string[];
var view: string[] = [];
let view: string[];
let view: string[] = [];
Even though the TypeScript documentation states that it should work as expected.
Click here for TypeScript basic types documentation Or visit this link for the TypeScript tutorial
However, when I use the following code snippet:
view: string[];
constructor() {
this.view = [];
}
Everything works fine without any issues.
Could someone please explain why the following code results in an error:
export class TextComponent implements OnInit {
let view: string[] = [];
ngOnInit() {
....
}
}
And why using any of the previously mentioned variants always leads to the error:
ngOnInit is not defined