skip to Main Content

I wan’t displaying all users in my admin page.
I don’t found and i don’t know the function symfony to return all users in angular. Would you know the code please?
I use a db, with mysql and phpmyadmin

I know the problem comes from my symfony function. I would like the function that returns all the user listed backoffice

My function in UserController.php :

/**
 * @RestGet("/allUsers")
 */
public function getAllUsers()
{
    // TODO: récupérer tout les utilisateurs de la base de donnée.
    $user = $this->get('security.token_storage')->getDoctrine()->getUser();;

    return new Response($user);
}

My userService.ts :

getAllUsers() {
 return this.api.get('api/user/allUsers');
}

I use Angular 7 and Symfony 4

I return the current user whit that function in my UserController.php

public function getUser()
{
    $user = $this->get('security.token_storage')->getToken()->getUser();
    $response = $this->serializer->serialize($user, 'json', SerializationContext::create()->setGroups(array('user.get')));

    return new Response($response);
}

2

Answers


  1. you didn’t provide your app component but i assume you have not made a method that gets your data from the service. ill share one of my Methods for getting a data from a service.

    If you use an Http request (you use Rest API) so :

    this is how your service should look :

    import { Injectable } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    import { Observable } from 'rxjs';
    import { Container } from '../Container';
    
    
    
      @Injectable({
        providedIn: 'root'
      })
      export class MarinServiceService {
    
        Marinurl : string = 'http://192.168.0.83/MarinApi/api/Values';
        constructor(private http : HttpClient) { }
    
    
        public getAllContainers():Observable<Container[]>{
          return this.http.get<Container[]>(this.Marinurl)
        }
    }
    

    Change the Method name and Object according to your names.

    And here is the Component Method :

    users  = [];
    
    ngOnInit() {
      this.marinService.getAllContainers().subscribe((result)=>{
        this.users = result;
    

    Change it according to your names.

    Basically you need to subscribe to your method -> think of it like a viewer subscribing to a YouTube channel. and the keeps looking for new videos.

    Login or Signup to reply.
  2. Simple API

    call that api Using Angular HTTPClient

    // this.http.get("http://jsonplaceholder.typicode.com/users").
    //     subscribe((data) ⇒ console.log(data))
    
    this.http.get("this is your servie URL ").
              subscribe((data) ⇒ console.log(data))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search