Search code examples
androidiosionic2cross-platformionic2-select

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>

How to use selectOptions multi-lang?

Don't work this line [selectOptions]="{{ 'selectOptionsBranch' | translate }}"


Solution

  • In html change [selectOptions]="{{ 'selectOptionsBranch' | translate }}" to [selectOptions]="selectOptionsBranch":

    In Typescript use this code :

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