While in the process of developing an angular application, I stumbled upon a peculiar issue. Some time ago, I crafted this piece of code which performed flawlessly:
selectedGeoArea: any
receiveStoreEvent(event) {
switch (event.constructor) {
case City:
console.log("city")
break
case Province:
console.log("province")
break
case String:
console.log("region")
break
}
this.selectedGeoArea = event
}
Now, selectedGeoArea
is then sent as input to another component
<text-search [selectedGeoArea]="selectedGeoArea"></text-search>
export class TextSearchComponent {
@Input() selectedGeoArea: any
buildQuery(): string {
switch (this.selectedGeoArea) {
case City:
return `${this.addressQuery}, ${this.selectedGeoArea.name}, ${this.selectedGeoArea.province.code}, ${this.selectedGeoArea.province.region}`
case Province:
return `${this.addressQuery}, ${this.selectedGeoArea.code}, ${this.selectedGeoArea.region}`
case String:
return `${this.addressQuery}, ${this.selectedGeoArea}`
}
return this.addressQuery
}
The issue at hand is that buildQuery()
consistently returns the value of addressQuery
, signifying that the switch statement is not functioning correctly. The selectedGeoArea
does have the correct value and type as assigned in receiveStoreEvent()
.
What could potentially be missing from this scenario?