How to access a side menu item through to a simple button?

Hi,

I want to click in a simple button as if I had clicked in a side menu item.
Here is my plunker
Any ideas?
Regards,

Luiz Almeida

@luizalmeida

I don’t really understand your question, you want to add an action to your child button, right? Then you can simply do an ng-click directive towards a goTo() method, witch will do a $state.go(‘app.url’), maybe?

Hi Devniz.

No. I just want to show the page “Item 2” from any other page as if I had clicked in the side-menu item.
When I click in the “Go to Item 2” button the result is different from when I call the page “Item 2” by the side menu.

What do you mean by “The result is different when I call the page Item 2 by the side menu”? In your plunker the redirection does work fine, are you talking about the transition, the way the page is rendered?

The problem is on the header.
This is what I got when I click in the side menu and this what I got when I click in the button.
I don’t want the back button (square in red)
I wan’t to click in the button and have the same result as I have when I click in the side menu.

Ok got it! Sorry but your post was very unclear until now. Well, what you can do it’s every time before to do your redirection, you set the next view as a root view and it will automatically remove the Back button and put your hamburger side-menu icons instead:

$scope.$on('$ionicView.beforeEnter', function() { $ionicHistory.nextViewOptions({ historyRoot: true }); })

Hi Devniz.

Im my ionic project I added your tip before the $state.go(‘app.item2’) call.

$scope.goToItem2 = function () {

$scope.$on(’$ionicView.beforeEnter’, function () {
$ionicHistory.nextViewOptions({
historyRoot: true
});
});

$state.go(‘app.item2’);
}

Am I doing it right?
Unfortunately I’m getting the same behavior.
In plunker it is not working (my bet is the $ionicHistory dependency or someone else)
Regards,

Luiz Almeida

Hi.

I got it. :smile:
I just add your tip without the event '$ionicView.beforeEnter'.
Let me see if I can update the plunker and share the result.

You don’t need to put this piece of code inside your function, it’s a listener. (separate function).

To put the plunker working I had to do this:

$scope.goToItem2 = function() {

$ionicHistory.nextViewOptions({
historyRoot: true
});

$state.go(‘app.item2’);
}

To put my ionic project working I did what you said (outside my function):

$scope.$on(’$ionicView.beforeEnter’, function () {
$ionicHistory.nextViewOptions({
historyRoot: true
});
});

I’ll do some more tests.
Thank you very much.

Ok cool, happy that it does work for you.