-1

I want to implement Angular example which gets list from rest API. I tried this:

SQL query:

    @Override
    public Iterable<Merchants> findAll() {
        String hql = "select e from " + Merchants.class.getName() + " e";
        TypedQuery<Merchants> query = entityManager.createQuery(hql, Merchants.class);
        List<Merchants> merchants = query.getResultList();
        return merchants;
    }

Rest controller:

@RestController
@RequestMapping("/merchants")
public class MerchantController {

    @GetMapping("/list")
    public Iterable<Merchants> getMerchantsList() {
        return merchantRepository
                .findAll();
    }
}

Service:

@Injectable({
  providedIn: 'root'
})
export class MerchantService {

  constructor(private http: HttpClient) {
  }    
  getList() {
    return this.http.get("...../api/merchants/list");
  }
}

Component:

@Component({
  selector: 'app-terminal',
  templateUrl: './terminal.component.html',
  styleUrls: ['./terminal.component.scss']
})
export class TerminalComponent implements OnInit {
  merchants: Merchant[];
  constructor(private merchantService: MerchantService,
              private router: Router,
              private route: ActivatedRoute) {
  }   

  ngOnInit() {               
    this.merchantService.getList();
  }    
}

But when I lock the component via web page nothing happens. Can you give me some advice where I'm wrong? Probably my typescript is somewhere incorrect?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

0

You need to call subscribe on the Observable, otherwise it won't make the HTTP request

ngOnInit() {               
  this.merchantService.getList().subscribe(res => {
    console.log("The response is", res); 
  });
}    
user184994
  • 17,791
  • 1
  • 46
  • 52