I am trying to grasp the concept of 'this'. In a specific scenario, I keep encountering the error message "this.markerArray is undefined". However, I have defined markerArray as a global variable so I am puzzled by this issue.
@Component({
selector: 'app-open-street-map',
templateUrl: './open-street-map.component.html',
styleUrls: ['./open-street-map.component.css']
})
export class OpenStreetMapComponent implements OnInit {
@Output() private add = new EventEmitter();
@Output() private edit = new EventEmitter<number>();
artworkList: Artwork[];
map;
//declaration made here
markerArray = [];
constructor() { }
ngOnInit() {
});
buildMarkers(artworkList) {
for (let artwork of artworkList) {
const marker = this.buildPopup(artwork);
this.markers.push(marker);
}
console.log("marker", marker);
console.log("markerArray", this.markerArray);
}
}
I have excluded a significant amount of code from this TypeScript page! The objective is to populate the markerArray
. While I acknowledged your advice on initializing it, I have done so, but all array inputs still show as "undefined"?!