0

У меня есть БД, с которой я хочу вывести данные. Backend:

[HttpGet("{id}")]
    public async Task<IActionResult> GetIdUser(int id)
    {
        if (id!= null)
        {
            var result = _context.Users.FirstOrDefaultAsync(c => c.Id== id);
            return Ok(await result);
        }
        else
        {
            return BadRequest("NotFoundId");
        }
    }

Сервис:

    user:any;
      getUserById(id:int):void{
          this.httpClient
            .get<Clothes>(`${environment.apiUrl}/${this.url}/${id}`)
            .pipe(tap(result => this.user = result));
  }

Компонент:

user:any;
  private subscription: Subscription;
  Id:string;
  constructor(private userService:UserService, private activateRoute: ActivatedRoute) {
    this.subscription = this.activateRoute.params.subscribe(params => this.Id= params['id'] );
    this.user= this.userService.user;

  }

  ngOnInit(): void {

    this.userService. getUserById(this.Id);
  }

HTML:

<app-carousel-info [user]="user">

</app-carousel-info-info>
<div class="col-lg-6 col-sm-1">
  <span class="text-start ps-lg-5 ">Name: {{user.name}}  </span>
  <h1 class="p-lg-0 ps-lg-5 pt-lg-3 padding-info">age: {{user.age}}
</div>

Но данные не приходят с сервера. Адрес на контроллер правильный, я уверен. Помогите, пожалуйста.

2
  • и что сервер говорит? он ошибку выдает, пустой массив или еще что? на каком этапе проблема? 30 авг 2022 в 1:55
  • Выводил через console.log, но тип undefined
    – Bi1s
    30 авг 2022 в 1:57

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.