0

I'm getting false in the response from the api. If I console.log the result then it shows {}. What I want to do is, if the response is false then redirect to the homepage. But the false condition is not working. Below is my code:

this.sub = this.route.params.subscribe(params => {
    this.token = params['Token'];
    this.common.createAPIService('api/users/recoverpassword/ValidateLink?Token=' + this.token + '', '').subscribe((result: any) => {

        console.log(result);
        if (!result || result == {} || result == false) {
            this.common.ShowNotification("Change Password", "Invalid Request", "error");
            // setTimeout(function () {
            //     window.location.href = "#";
            // }, 3000);
            console.log(12);
            this.zone.run(() => this.router.navigateByUrl("/home/" + "Mumbai"));
        }
    });
});

I tried !result, {}, even result == false but it's not working. The alert in condition or console.log not coming. Please help.

ProgrammerPer
  • 1,125
  • 1
  • 11
  • 26
Sagar Kodte
  • 3,723
  • 4
  • 23
  • 52

2 Answers2

0

Use === instead of ==

 if (!result || result === {} || result === false) {
                    this.common.ShowNotification("Change Password", "Invalid Request", "error");
                    // setTimeout(function () {
                    //     window.location.href = "#";
                    // }, 3000);
                    console.log(12);
                    this.zone.run(() => this.router.navigateByUrl("/home/" + "Mumbai"));
                }

For more you can refer this == vs ===

Roopak Puthenveettil
  • 1,387
  • 2
  • 13
  • 27
0

In Javascript, you should check whether it is truthy or falsy in your condition

Refer https://developer.mozilla.org/en-US/docs/Glossary/Truthy

Hari Prathap
  • 102
  • 7