Search code examples
angularionic3side-menu

Ionic 3 - Side menu , change side dynamically


I want to change the direction of the side menu automatically when i change the language (rtl and ltr) i tried this code in the page app.html

<ion-menu [side]="isRtl?'right':'left'" [content]="content">

How can i change the value of 'isRtl' from another page or example "home.ts" ?

'isRtl' is declared in 'app.component.ts' any help guys ?


Solution

  • Use event emitor for cross component to transfer data between components

    //Home component.ts
    import { Events } from 'ionic-angular';  
       constructor(public events: Events) {
          directioChange(user) {
                this.events.publish('directiochanged', 'true');
          }
       }
    
    
    //App.component.ts
    constructor(public events: Events) {
         events.subscribe('directiochanged', (direction) => { 
               this.isRtl = direction;console.log(direction);
         });
    }
    

    not only from home component, you can set from anywhere in you project