Call ion-view in function

Asked

Viewed 783 times

1

I’m starting in Ionic and Angularjs, already googlei enough and found nothing about this simple doubt.

I can navigate well between the ion-view "Page1" and "Page2" using buttons:

<ion-view view-title="Page1">
  <ion-content>
    <h1>Page 1</h1>
    <a class="button icon icon-right ion-chevron-right" href="#/app/page2">Page 2</a>
  </ion-content>
</ion-view>

<ion-view view-title="Page2">
  <ion-content>
    <h1>Page 2</h1>
    <a class="button icon icon-right ion-chevron-right" href="#/app/page1">Page 1</a>
  </ion-content>
</ion-view>

But I would like to perform this through a function:

function EventoTal(){

      carregue("page2");

}

No need to click the button.

In jQuery $(elemento).show();

1 answer

0


It won’t work with Ionic, but since it’s web-based, we can try the following which is the code equivalent to what the <a href="#/app/page2">Page 2</a> ago:

location.hash = "/app/page2";

Or so to keep page stack history:

if(history.pushState) {
    history.pushState(null, null, '#/app/page2');
}
else {
    location.hash = '#/app/page2';
}
  • Thank you very much! That’s right! I had tried to seem but without success.

  • @Patricklobo, did it really work out? Hehe. I’m glad I helped, and I’ve never had contact with Ionic, although I’ve read some things about, so the answer was based on my web knowledge. Hehe.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.