0

trying to retrieve the values ​​from a query set on a service. Required show the result of said query as a message in an alert.

the query is functional and extracts the data I need

client.service

searchType(his: string): Observable<any> {
        return this.http.get(`${environment.url}rute?param=${his}`, this.httpOptions);
      }

since the controller of other page consume the query created in the service, with parameter add

pageone.page.ts

 this.client.searchType(1).subscribe(val => { console.log(val.column) });

applying console.log can get the data I require

Data retorned from database Please, verify the observations idMensaje: 30121!!

Problem

  1. Required add this value in varible tipo string

Varible defined ValueOpt = ""

tests

this.client.searchType(1).subscribe(val => { this.ValueOpt = val.Column});
console.log(this.ValueOpt )

I try in the previous way to add the data obtained from the query in the variable ValueOpt , but it does not. As I modify my instruction to be able to have in this.ValueOpt the result of this query.

the procces realiced in the event

ngOnInit() {
 this.client.searchType(1).subscribe(val => { this.ValueOpt = val.Column});
 console.log(this.ValueOpt)
 }
Ferkin San
  • 115
  • 3

1 Answers1

1

i suggest

ngOnInit() {
  this.foo()
}

async foo() {
  const val = await this.client.searchType(1).toPromise();
  console.log(val.column)
}
HolyMarsia
  • 124
  • 1
  • 2