让input控件可以输入数字显示text

html这样写:
[attr.type]="displayText?'text':'number'" step="1" [(ngModel)]="displayPage">
ts文件中:

  displayText = true;
  set displayPage(value: any) {
    let v = Number(value);
    if (this.pageDatas.length === 0) {
        this.currentPage = 0;
    }

    if (v && v >= 1) {
        v = Math.round(v);
        v = v - 1;
        if (v >= this.pageDatas.length) {
            v = this.pageDatas.length - 1;
        }
        this.currentPage = v;
    }
}

get displayPage(): any {
    if (this.pageDatas.length === 0) {
        return '';
    }
    if (this.displayText) {
        return (this.currentPage + 1) + '/' + this.pageDatas.length;
    } else {
        return this.currentPage + 1;
    }
}

你可能感兴趣的:(让input控件可以输入数字显示text)