离子2:如何使用多种语言进行选择离子选择[selectOptions]?

时间:2017-04-17 05:49:29

标签: android ios ionic2 cross-platform ionic2-select

 <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 multi-lang?

请勿使用此行[selectOptions]="{{ 'selectOptionsBranch' | translate }}"

1 个答案:

答案 0 :(得分:0)

在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;
      }
    )
  }
}