-1

I tried to do this, but it doesn't work. Any help is appreciated thanks!

    export class OuterClass {
    let isEffectiveUrl = (url:string) => {
            let tmpRes:boolean
            this.http.get(url).subscribe((result) => {
                  tmpRes = Object.keys(result).length > 0;
                });
            return tmpRes;
          }
     }
Sukey
  • 19
  • 3

1 Answers1

0

You're setting isEffectiveUrl to be a function, not the resulting evaluation. One way to do this would create a local variable and then execute your http.get within a function or one of your lifecycle hooks.

e.g.

export class OuterClass {

  isEffectiveUrl: boolean = false;

  testUrl(url: string): void {
    this.http.get(url).subscribe((result) => {
      this.isEffectiveUrl = Object.keys(result).length > 0;
    });
  }

}

Just remember, this is a reactive model. So what's being run in the subscribe block is asynchronous.

mfaith
  • 115
  • 3
  • 11