Ionic 2:How 为 select 或 ion-select [selectOptions] 使用多语言?
Ionic 2:How to use multi-lang for selector ion-select [selectOptions]?
<ion-item>
<ion-label >{{ 'branch' | translate }}</ion-label>
<ion-select [(ngModel)]="defualtBranch"
okText="{{ 'okText' | translate }}"
cancelText="{{ 'cancelText' | translate }}"
[selectOptions]="{{ 'selectOptionsBranch' | translate }}" >
<ion-option *ngFor="let branch of branchs; let i=index" value="{{branch.BranchCode}}">
{{branch.BranchName}}
</ion-option>
</ion-select>
</ion-item>
如何使用selectOptions多语言?
这条线不要工作[selectOptions]="{{ 'selectOptionsBranch' | translate }}"
在 html 中将 [selectOptions]="{{ 'selectOptionsBranch' | translate }}"
更改为 [selectOptions]="selectOptionsBranch"
:
在 Typescript 中使用此代码:
import { TranslateService } from 'ng2-translate';
export class IntroPage {
selectOptionsBranch:any;
constructor(public navCtrl: NavController,translate: TranslateService) {
translate.use("fa");
translate.get('selectOptionsBranch').subscribe(
value => {
console.log(value);
this.selectOptionsBranch = value;
}
)
}
}
<ion-item>
<ion-label >{{ 'branch' | translate }}</ion-label>
<ion-select [(ngModel)]="defualtBranch"
okText="{{ 'okText' | translate }}"
cancelText="{{ 'cancelText' | translate }}"
[selectOptions]="{{ 'selectOptionsBranch' | translate }}" >
<ion-option *ngFor="let branch of branchs; let i=index" value="{{branch.BranchCode}}">
{{branch.BranchName}}
</ion-option>
</ion-select>
</ion-item>
如何使用selectOptions多语言?
这条线不要工作[selectOptions]="{{ 'selectOptionsBranch' | translate }}"
在 html 中将 [selectOptions]="{{ 'selectOptionsBranch' | translate }}"
更改为 [selectOptions]="selectOptionsBranch"
:
在 Typescript 中使用此代码:
import { TranslateService } from 'ng2-translate';
export class IntroPage {
selectOptionsBranch:any;
constructor(public navCtrl: NavController,translate: TranslateService) {
translate.use("fa");
translate.get('selectOptionsBranch').subscribe(
value => {
console.log(value);
this.selectOptionsBranch = value;
}
)
}
}