如何在打字稿中检查空字符串

时间:2018-07-15 09:30:36

标签: typescript angular6

我有以下课程

fields

export class PracticeQuestionsListAPI { 'list':UserOverview[]; 'page-info':string; constructor(public pageState:string, public usersList:UserOverview[]){ this['page-state'] = pageState; this['users-list'] = usersList; } } 组件的HTML中,仅当Angular不是空字符串时,才想显示button。我该怎么办?

我已经写过类似的东西,但是没有编译。

page-state

我也尝试过<button *ngIf="!this.users['page-state'].isEmpty()" (click)="getNextPage()" id="next-page-button" class="btn content-div__button--blue btn-sm">Next Page</button> ,但这也不能编译

1 个答案:

答案 0 :(得分:1)

这应该很好

<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>

或此

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