我正在尝试通过选择器将组件中的位置变量绑定到商店中的另一个变量,其中 ngrx v13 有角度,但是当我将带有属性的变量放入 HTML 中时出现错误:
错误消息:“可观察”类型上不存在属性“名称”
那是我的代码:
应用程序选择器.ts
import { createSelector } from "@ngrx/store";
export const CurrentLocationSelector=(state:AppState) => state.currentLocation;
export const getCurrentLocation = createSelector(
CurrentLocationSelector,
(currentLocation: any) => {
return [...new Set(currentLocation)];
}
);
那是我的 AppState:
interface AppState{
darktheme:boolean;
temperatureUnit:string;
currentLocation:any; // object with the current location
locationAutoComplete:any[]; // array that contains the result from the autocomplete
locationCurrentWeather:CurrentItem | null;
Forecast5Days:ForecastItem[];
Favorites:FavoriteItem[];
loading:boolean;
getData:boolean;
}
在我的组件中我写道: current-weather.component.html
<div class="left">
<span class="locationName">{{location$.name}}</span>
<span class="date">{{currentFullDate}}</span>
<div class="weatherDescription">
<img [src]="imageCurrentWeather" class="weatherIcon">
<div class="weatherText">{{CurrentWeather.WeatherText}}</div>
</div>
<h1 [innerHTML]="CurrentWeather.Temperature + ' ' + currentUnit"></h1>
</div>
在我的current-weather.component.ts我写
location$ = this.store.pipe(select(CurrentLocationSelector))