You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<nz-option *ngFor="let x of this.MyTypeList" [nzValue]="x" [nzLabel]="this.Convert(x)">
<nz-option *ngFor="let x of this.MyTypeList" [nzValue]="x">{{ x | myTypePipe }}
我需要使用 nz-select 的 nz-option 时, 将 enum 枚举出来, 放在 nzValue / nzLabel 上, 但是 nzLabel 我想显示中文, 比方:
export enum MyType { Public = 0, Private = 1 } // 希望能在 Label 显示为 "公开, 私有"
<nz-option *ngFor="let x of this.MyTypeList" [nzValue]="x" [nzLabel]="this.Convert(x)">
<nz-option *ngFor="let x of this.MyTypeList" [nzValue]="x">{{ x | myTypePipe }}
ngFor 都没问题, nzValue 也正确 (0, 1). 但是 nzLabel 用了以上两种方法都无法正确.
其中第一种方式 -> 另外做一个 Convert function, 貌似根本编译不过, (试过用 member funciton 也试过用 static function 都不行)
第二种方法能过 但是下拉选单中看不到 Label. (产生的 option 的数量正确, 但是就是看不见. 貌似所有的 Label 都是空字符串, 但事实上在 pipe 中用 console.log 检查过都有正确转换)
再补充一点, 若不考虑转换成中文, nz-option 的 nzValue: 0, 1 以及 nz Label 显示 Public, Private 都没问题
若是定义成 export enum MyType { Public = '公开', Private = '私有' } 也能显示出中文, 但是 value 就不再是 0/1. 而且与数据库相关, 我需要保持使用的都是 0/1 以及 Public/Private
The text was updated successfully, but these errors were encountered: