Manu Chadha
Manu Chadha

Reputation: 16747

How to check for an empty string in typescript

I have the following class

export class PracticeQuestionsListAPI {
  'list':UserOverview[];
  'page-info':string;
  constructor(public pageState:string, public usersList:UserOverview[]){
    this['page-state'] = pageState;
    this['users-list'] = usersList;
  }
}

In my Angular's component's HTML, I want to show a button only if page-state is not an empty string. How could I do it?

I have written something like this but it doesn't compile.

<button *ngIf="!this.users['page-state'].isEmpty()" (click)="getNextPage()" id="next-page-button" class="btn content-div__button--blue btn-sm">Next Page</button>

I also tried *ngIf="!(this.questions['page-state'] =="")" but that doesn't compile either

Upvotes: 0

Views: 8797

Answers (1)

Roopesh Kumar Ramesh
Roopesh Kumar Ramesh

Reputation: 158

this should work fine

<button *ngIf="this.users['page-state'].length>0" (click)="getNextPage()" id="next-page-button" class="btn content-div__button--blue btn-sm">Next Page</button>

or this

<button *ngIf="this.users['page-state'].length>!==''" (click)="getNextPage()" id="next-page-button" class="btn content-div__button--blue btn-sm">Next Page</button>

Upvotes: 2

Related Questions