jeudi 2 septembre 2021

Having a lint error ethir with the use of a ternary operator or with a conventional if statement in angular

im trying to implement a conditional inside a subscription of a function that doesn´t return anything(void), but keep receiving this error , no matters if i set it as a ternary operator or with conventional if:

Expected an assignment or function call and instead saw an expression 

this is my function:

public getSomeSTuffs(): void {
    
   
        this._stuffsService.getStuffData$().subscribe((stuff: Stuffs) => {
         ===>CONVENTIONAL WAY<===
          if (stuff) {
            this.loading = false;
            this.stuffView = stuff;
          }
          if (!stuff) {
            this.loading = false;
            this.stuffView = undefined;
          }


       ===>USING TERNARY OPERATOR<===
         stuff?(this.loading = false,this.stuffView = stuff):(this.loading = false,this.stuffView = undefined)
        })
      

  }

Any help about how can i improve this situation. Thanks in advance!!

Aucun commentaire:

Enregistrer un commentaire