Call a method on initial page index.html

I am trying to call a method for the initial page index.html… I need to call a facebook login method onclick at the index.html page… and when I call the method I receive error on the console

Can’t find variable: method_name

is it possible when init the app to call a method ?
thanks

// Init App
var app = new Framework7({
  id: 'io.framework7.testapp',
  root: '#app',
  theme: theme,
  view: {
    stackPages: true,
  },
  data: function () {
    return {
      user: {
        firstName: 'John',
        lastName: 'Doe',
      },
      language: "en",
    };
  },

  methods: {
    helloWorld: function () {
      app.dialog.alert('Hello World!');
    },

loginWithFB : function () {
     console.log('loginWithFB!');
    },

  },


  on: {
    pageInit: function() {
      console.log('pageInit');

      helloWorld(); // this gives me error Can’t find variable: helloWorld

    }
  },

in my index.html
this below do nothing!

<button href="#" @click="loginWithFB()" class="button button-big button-round button-fill color-tile">Login With Facebook</button>

It is not a global method to call it like helloWorld. You need to call it as app.methods.helloWorld() or $root.helloWorld() in component context

1 Like

thanks Vladimir! I tried this app.methods.helloWorld()… can index.html be a component page too?

This maybe usefulhttp://forum.framework7.io/t/is-there-better-way-to-do-something-before-the-first-page-displayed/5336

1 Like

thanks a lot for this info… this helps too… the problem in my index.html I have a autocomplete a search and many things… this works fine inside a page but not in the index.html

thanks for tips

If I call the method like app.methods.helloWorld() in the index.html like this it works:

<button href="#" onclick="loginWithFB()" class="button button-big button-round button-fill color-tile">Login With Facebook</button>

but using

@click it does nothing:

<button href="#" @click="loginWithFB()" class="button button-big button-round button-fill color-tile">Login With Facebook</button>

anyway to make the @click event to work in the index.html page as well?

onclick by the way does not work on IOS… only @click

thanks

You need to load home page as component in this case http://framework7.io/docs/view.html#initial-page-route

1 Like

thanks for the tips! :+1: