I am currently working on project where I use angular-google-map (agm), and I use different polygons to display different things. Now I want to draw on map so I get collection of coordinates which I can use problem is my object array doesn't update.
TLDR: Object array doesn't update when I use .push.
home.component.ts
export class HomeComponent implements OnInit {
ngOnInit(): void {
}
constructor(private cr: ChangeDetectorRef) { }
//this is my polygon with initial values
pathsLs: any[] = [[
{ lat: 43.51270075713179, lng: 16.468134790981548 },
{ lat: 43.51205153579524, lng: 16.46757689150645 },
{ lat: 43.5119745090715, lng: 16.466895610416667 },
{ lat: 43.51273927004248, lng: 16.466659576023357 },
{ lat: 43.51284380496191, lng: 16.467753917301433 },
]]
pointList: { lat: number; lng: number }[] = [];
//this is function I use to update my Object array
addSomething() {
this.pathsLs.push(this.pointList);
this.pathsLs = [...this.pathsLs];
this.cr.detectChanges();
}
Problem is when this function is called I can see on console.log(this.pathsLs) that it's updated and it even draws polygon on map but when I refresh its all back to previous(initial value). I guess that I am asking is there a way to physically see this change for example:
if I do something like this this.pathsLs.push([{ lat: 43.51174, lng: 16.46538 }])
to actually get in my typescript this:
pathsLs: any[] = [[
{ lat: 43.51270075713179, lng: 16.468134790981548 },
{ lat: 43.51205153579524, lng: 16.46757689150645 },
{ lat: 43.5119745090715, lng: 16.466895610416667 },
{ lat: 43.51273927004248, lng: 16.466659576023357 },
{ lat: 43.51284380496191, lng: 16.467753917301433 },
],[{ lat: 43.51174, lng: 16.46538 }] <-- newly added
]