Компонент:
applicants: UserProfile[];
ngOnInit() {
this.store
.pipe(select(fromRootUserProfileState.getUserProfiles))
.subscribe((userProfiles: UserProfile[]) => {
this.applicants = userProfiles;
console.log('this.applicants:', this.applicants);
});
}
Интерфейс UserProfile:
export interface UserProfile {
id: number;
fullName: string;
roles?: Role[];
windowsAccount?: string;
firstName?: string;
lastName?: string;
email?: string;
managerName?: string;
managerId?: number;
managerEmail?: string;
companyId?: number;
companyName?: string;
countryId?: number;
country: Country;
countryName?: string;
}
Эффект NgRx:
@Injectable()
export class UserProfileEffects {
constructor(
private actions$: Actions,
private userProfileService: UserProfileService
) {}
@Effect()
loadUserProfiles$: Observable<Action> = this.actions$.pipe(
ofType(userProfileActions.UserProfileActionTypes.LoadUPs),
mergeMap((action: userProfileActions.LoadUPs) =>
this.userProfileService.getUserProfiles().pipe(
map(
(userProfiles: Array<UserProfile>) =>
new userProfileActions.LoadSuccessUPs(userProfiles)
),
catchError((err) => of(new userProfileActions.LoadFailUPs(err)))
)
)
);
}
Служба:
getUserProfiles(): Observable<UserProfile[]> {
return this.http.get<UserProfile[]>(this.baseUrl + 'userprofiles/getuserprofiles');
}
Backend API (. Net Core):
[HttpGet("[action]")]
public async Task<IActionResult> GetUserProfiles()
{
var userProfiles = await _userProfileRepository.GetUserProfiles();
var userProfileViewModels = _mapper.Map<IEnumerable<UserProfileViewModel>>(userProfiles);
return Ok(userProfileViewModels);
}
Но в компоненте я не могу рассматривать свой массив «заявителей» как правильный массив, это своего рода объект. Это происходит по всему моему коду, почему я не получаю массив объектов, как я определил явно?
![enter image description here](https://i.stack.imgur.com/6imQG.png)
![enter image description here](https://i.stack.imgur.com/K5win.png)