myApp sidemenu Example


#1

Sorry for my bad english :S

I download the “myApp sidemenu” example and it work prefectly. So i try to add a “Home-Button” in the header of the Side-Menu (works). So how i can add the function to go home?

Im a beginner in the world of angularjs and ionic :S

<ion-side-menu side="left">
<header class="bar bar-header bar-stable">
  <button menu-close class="button button-icon icon ion-home"></button>
  <h1 class="title">Navigation</h1>
</header>
<ion-content class="has-header">

#2

You can use ng-click directive on the button and create a function into the controller that use the “go” instruction.


#3

thx biapar :smiley:

can u write the code down :smiley:


#4

Depends on how routing states are setup but it’d be something like this:

$state.go('app.home')

#5

it works now :smiley:

menu.html

<button nav-clear menu-close class="button button-icon icon ion-home" ng-controller="goToHome" ng-click="goHome()"></button>

controllers.js

angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope) {
})

.controller('goToHome', function($scope, $location) {
  $scope.goHome = function () {
     $location.url('/');
  }
})

#6

I personally try to avoid using the $location service with Ionic. It works, but it causes template ‘flashing’ when you’re transitioning between views. Instead, try to use $state.go or $state.transitionTo in order to leverage Ionic’s awesome transition animations.