Global function in ionic 5

Please how i can create function in app.compenent and call in other pages

Because you added the Angular Label, i assume you are using it, so you should get familiar with it. A Question like this would be easy for you then.

I only can repeat myself and refer to the Tour of Heroes Tutorial by Angular.

1 Like

To build on @EinfachHans’s (excellent as always) advice, the first goal is always to figure out the question you really want to ask, and we aren’t there yet. Components calling functions in other components breaks encapsulation, and is an antipattern. You likely want a service provider.

1 Like

app.comppnent.ts

import { Component, OnInit } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';


@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent implements OnInit {
  public selectedIndex = 0;

  public appPages = [
        {
      title: 'Health',
      url: '/blog',
      icon: 'medkit'
    },
    {
      title: 'Food',
      url: '/blog',
      icon: 'paw'  
    },
 
  ];
  //public labels = ['Family', 'Friends', 'Notes', 'Work', 'Travel', 'Reminders'];

  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,

  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
  
     
  }



  });
   }
     
     myFunction(){
   console.log('Helooo ');
     }

  ngOnInit() {
   

}


}

How i can call myFunction() in my page blog.ts like function global

I’m saying you don’t want to do that. You need to flip around the way you think from an imperative to a reactive/functional mindset. I realize that may be confusing or frustrating, but it is an absolute necessity if you don’t want to drive yourself crazy when trying to write webapps.