In my spring-boot back-end app, I have defined a query as shown below:
@Query("SELECT COUNT(*) "
+ "FROM Foo "
+ "WHERE name = :name and surname = :surname ")
Integer countByNameAndSurname(@Param("name") String name, @Param("surname") String surname);
While the query on the back-end side functions correctly, I am facing issues retrieving the integer value it returns on the front-end side developed with Angular 4. Despite numerous attempts, I have been unable to resolve this issue.
getCount() {
return this.http.get(this.actionUrl + this.param,{headers: DataService.getHeaders()})
.subscribe(response => {
console.log(response);
console.log(response.json());
this.countResult = response.json();
//return this.countResult;
return response.json();
})
}
(I even tried defining a return type as getCount(): number{...}
and returning the variable countResult
that is set inside the call, but without success.) This method resides within my service class. I attempted both to store it in a public variable this.countResult
for access from another class, and also to return the response.json()._body;
which holds the desired integer. The API call itself executes flawlessly. I have tested it multiple times.
However, I consistently receive a Subscriber object containing very little information. https://i.sstatic.net/8PR9r.png
The service is invoked in this manner:
var count = this.dataService.getCountExternalCvs();
console.log(count);
When printing the count
, it displays the subscriber object mentioned above.
The reason for using the .subscribe()
method is to avoid receiving a Promise and instead obtaining the raw value.
Here are the responses and processed JSON data displayed during the service call, alongside the subscriber object obtained when invoking
var count = this.dataService.getCountExternalCvs();
https://i.sstatic.net/MVUSw.png
Despite various attempts, I have not been able to circumvent the Subscriber object and retrieve the actual response.