Я столкнулся со странной проблемой при разработке приложения angular. Я написал этот фрагмент кода некоторое время go, и он отлично работает:
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
}
сейчас, selectedGeoArea
затем передается в качестве входных данных другому компоненту
<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
}
проблема в том, что buildQuery()
всегда возвращает значение addressQuery
, что означает, что коммутатор вообще не работает. selectedGeoArea
имеет правильное значение и тип, как указано в receiveStoreEvent()
.
что мне здесь не хватает?