Side menu with Tabs issue

Hi,

I am new to ionic framework.
I have designed a sample ionic app with sidemenu and tabs together. I have taken code from sample sidemenu and tabs app(Which has given in the site). But my side menu links are not functioning as expected. My sidemenu links and tab links navigating to different html screens.

Scenarios : 1. Click on home screen in side menu. 2. Click on More Facts in side menu 3. Now click on Home button in tabs(It is not displaying home.html screen. This is my main problem)

Please resolve this issue. It helps me a lot. Thanks in advance.

Ramprasad

Following is the code i have written.

<title>Tabs Example</title>

<link href="http://code.ionicframework.com/1.0.0-beta.14/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.0.0-beta.14/js/ionic.bundle.min.js"></script>
<ion-side-menus>
    
    <ion-side-menu-content ng-controller="NavCtrl">
      <ion-nav-bar class="bar-positive">
        <ion-nav-back-button class="button-icon ion-arrow-left-c">
        </ion-nav-back-button>
      
        <ion-nav-buttons side="left">
          <button class="button button-icon button-clear ion-navicon" ng-click="showMenu()">
          </button>
        </ion-nav-buttons>

        <ion-nav-buttons side="right">
          <button class="button button-icon button-clear ion-ios7-gear" ng-click="showRightMenu()">
          </button>
        </ion-nav-buttons>
      </ion-nav-bar>
      <ion-nav-view animation="slide-left-right"></ion-nav-view>
    </ion-side-menu-content> 
    
    <ion-side-menu side="left">
      <ion-header-bar class="bar bar-header bar-assertive">
        <h1 class="title">Left Menu</h1>
      </ion-header-bar>
      <ion-content has-header="true">
        <ul class="list">
          <li>
            <a class="item" menu-close nav-clear href="#/tab/home">Home</a>
          </li>
          <li>
            <a class="item" menu-close href="#/tab/facts">Facts</a>
          </li>
          <li>
            <a class="item" menu-close href="#/tab/facts2">More Facts</a>
          </li>
        </ul>
      </ion-content>
    </ion-side-menu>
  
    <ion-side-menu side="right">
      <ion-header-bar class="bar bar-header bar-dark">
        <h1 class="title">Right Menu</h1>
      </ion-header-bar>
      <ion-content>
        <ul class="list">
          <li>
            <a class="item" menu-close nav-clear href="#/search">Search</a>
          </li>
          <li>
            <a class="item" menu-close nav-clear href="#/settings">Settings</a>
          </li>
        </ul>
      </ion-content>
    </ion-side-menu>
    
  </ion-side-menus>



<script id="tabs.html" type="text/ng-template">
  <ion-tabs class="tabs-icon-top tabs-positive">

    <ion-tab title="Home" icon="ion-home"  href="#/tab/home">
      <ion-nav-view name="home-tab"></ion-nav-view>
    </ion-tab>

    <ion-tab title="About" icon="ion-ios7-information" href="#/tab/about">
      <ion-nav-view name="about-tab"></ion-nav-view>
    </ion-tab>

    <ion-tab title="Contact" icon="ion-ios7-world" ui-sref="tabs.contact">
      <ion-nav-view name="contact-tab"></ion-nav-view>
    </ion-tab>

  </ion-tabs>
</script>

<script id="home.html" type="text/ng-template">
  <ion-view title="Home">
    <ion-content>
      <p>Example of Ionic tabs. Navigate to each tab, and
      navigate to child views of each tab and notice how
      each tab has its own navigation history.</p>
      <p>
        <a class="button icon icon-right ion-chevron-right" href="#/tab/facts">Scientific Facts</a>
      </p>
    </ion-content>
  </ion-view>
</script>

<script id="facts.html" type="text/ng-template">
  
  <ion-view title="Facts">
    <ion-content>
      <p>Banging your head against a wall uses 150 calories an hour.</p>
      <p>Dogs have four toes on their hind feet, and five on their front feet.</p>
      <p>The ant can lift 50 times its own weight, can pull 30 times its own weight and always falls over on its right side when intoxicated.</p>
      <p>A cockroach will live nine days without it's head, before it starves to death.</p>
      <p>Polar bears are left handed.</p>
      <p>
        <a class="button icon ion-home" href="#/tab/home"> Home</a>
        <a class="button icon icon-right ion-chevron-right" href="#/tab/facts2">More Facts</a>
      </p>
        
    </ion-content>
  </ion-view>
</script>

<script id="facts2.html" type="text/ng-template">
  <ion-view title="Also Factual">
    <ion-content>
      <p>111,111,111 x 111,111,111 = 12,345,678,987,654,321</p>
      <p>1 in every 4 Americans has appeared on T.V.</p>
      <p>11% of the world is left-handed.</p>
      <p>1 in 8 Americans has worked at a McDonalds restaurant.</p>
      <p>$283,200 is the absolute highest amount of money you can win on Jeopardy.</p>
      <p>101 Dalmatians, Peter Pan, Lady and the Tramp, and Mulan are the only Disney cartoons where both parents are present and don't die throughout the movie.</p>
      <p>
        <a class="button icon ion-home" href="#/tab/home"> Home</a>
        <a class="button icon ion-chevron-left" href="#/tab/facts"> Scientific Facts</a>
      </p>
    </ion-content>
  </ion-view>
</script>

<script id="about.html" type="text/ng-template">
  <ion-view title="About">
    <ion-content>
      <h3>Create hybrid mobile apps with the web technologies you love.</h3>
      <p>Free and open source, Ionic offers a library of mobile-optimized HTML, CSS and JS components for building highly interactive apps.</p>
      <p>Built with Sass and optimized for AngularJS.</p>
      <p>
        <a class="button icon icon-right ion-chevron-right" href="#/tab/navstack">Tabs Nav Stack</a>
      </p>
    </ion-content>
  </ion-view>
</script>

<script id="nav-stack.html" type="text/ng-template">
  <ion-view title="Tab Nav Stack">
    <ion-content>
      <p><img src="http://ionicframework.com/img/diagrams/tabs-nav-stack.png" style="width:100%"></p>
    </ion-content>
  </ion-view>
</script>

<script id="contact.html" type="text/ng-template">
  <ion-view title="Contact">
    <ion-content>
      <p>@IonicFramework</p>
      <p>@DriftyCo</p>
    </ion-content>
  </ion-view>
</script>

<script id="settings.html" type="text/ng-template">
  <ion-view title="Settings">
    <ion-content>
      Settings page
    </ion-content>
  </ion-view>
</script>

<script id="search.html" type="text/ng-template">
  <ion-view title="Search">
    <ion-content>
      Search page
    </ion-content>
  </ion-view>
</script>

angular.module(‘ionicApp’, [‘ionic’])

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider
.state(‘search’, {
url: ‘/search’,
templateUrl: ‘search.html’
})
.state(‘settings’, {
url: ‘/settings’,
templateUrl: ‘settings.html’
})
.state(‘tabs’, {
url: “/tab”,
abstract: true,
templateUrl: “tabs.html”
})
.state(‘tabs.home’, {
url: “/home”,
views: {
‘home-tab’: {
templateUrl: “home.html”,
controller: ‘HomeTabCtrl’
}
}
})
.state(‘tabs.facts’, {
url: “/facts”,
views: {
‘home-tab’: {
templateUrl: “facts.html”
}
}
})
.state(‘tabs.facts2’, {
url: “/facts2”,
views: {
‘home-tab’: {
templateUrl: “facts2.html”
}
}
})
.state(‘tabs.about’, {
url: “/about”,
views: {
‘about-tab’: {
templateUrl: “about.html”
}
}
})
.state(‘tabs.navstack’, {
url: “/navstack”,
views: {
‘about-tab’: {
templateUrl: “nav-stack.html”
}
}
})
.state(‘tabs.contact’, {
url: “/contact”,
views: {
‘contact-tab’: {
templateUrl: “contact.html”
}
}
});

$urlRouterProvider.otherwise("/tab/home");

})
.controller(‘NavCtrl’, function($scope, $ionicSideMenuDelegate) {
$scope.showMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
$scope.showRightMenu = function () {
$ionicSideMenuDelegate.toggleRight();
};
})
.controller(‘HomeTabCtrl’, function($scope) {
});

It’s probably easiest to start with the side menu starter, and then add the tabs to it.

The trick to making it work (for me) was getting the nesting and naming of the parent/child states and the parent/child views right. What I ended up with is this construct in the routing/state provider declaration for my “tabs” page:

$stateProvider
  .state('app.main', {
    url: "/main",
    abstract: true,
    views: {
      'menuContent@app': {
        templateUrl: "js/app/main/tabs.html"
      }
    }
  })

What this says is that your tabs template should be loaded into the “menuContent” view so that it’s properly nested “under” the menu. Now the trick was in the “menuContent@app” construct where you declare the parent view (“menuContent”) of your tabs page.

If you just code “menuContent” and not “menuContent@app” then it’s unable to find the parent (menu) view.
You have to add the “@app” so that Angular (UI-Router) knows in which UI-Router state (‘app’) the view (‘menuContent’) was declared.

(this @ syntax is called “absolute naming” of a view)

By the way, I’ve made a complete starter app here which contains the side menus and tabs in one app and a bunch of other stuff:

https://github.com/leob/ionic-quickstarter

It contains the implementation of side menu + tabs as described above. Installing it is very simple, the README contains step-by-step instructions.

Sorry for the late reply.
It was very nice app. While i was running, facing some errors. Is there any way to get this .apk file.
I don’t want to place my files inside src folder. I just want to place my files inside www folder.

I am providing this plunker http://codepen.io/gnomeontherun/pen/tbvdH.
In this example also we are facing the same problem. Will you please update this plunker.

Thanks in advance
Ramprasad

Not quite understanding what you mean.

Did you try to install and run my “quickstarter” app according to the instructions in the README ? And if yes did you get “errors” while running it (as you suggest) and if so what kind of “errors” were those?

And lastly what do you mean by “is there any way to get this .apk file” ? The README contains instructions on how to run in “dev” mode (‘ionic serve’) but also how to build/run in ‘producton’ mode on a device (‘gulp build’ and ‘ionic run’).

If you to just want to create and APK which you can manually install on a device then do "ionic buid’ instead of “ionic run”.

Just have a look at my code and you’ll see how the side menu and tabs work, that should be enough, I’m not going to update other people’s plunkers, lol …

My app name is starter.

  1. git clone https://github.com/leob/ionic-quickstarter
  2. mv ionic-quickstarter starter
  3. cd starter
  4. I changed app name with starter in following files as you suggest
    a. ionic.project
    b. config.xml
  5. Inside app i ran the following commands
    a. npm install
    b. bower install (‘bower’ is not recognized as an internal or external command,
    operable program or batch file.)
    c. ionic state restore --plugins
    d. ionic platform add android
    e. ionic serve (When i ran this command following error is showing in browser window)
    Error: ENOENT: no such file or directory, open ‘E:\ionicworkspace\starter\src\index.html’

Thanks in advance
Ramprasad

Try to run with “ionic serve -c -l” (with the “labs” option, and showing errors in the console).

Try it, I’m pretty sure it will work then. If not, look at the errors in the console (terminal).

Now i am getting the following error

ionic $ E:\ionicworkspace\app\node_modules\gulp-sass\node_modules\node-sass\lib
index.js:22
throw new Error(’libsass bindings not found. Try reinstalling node-sass?
’);
^

Error: libsass bindings not found. Try reinstalling node-sass?
at getBinding (E:\ionicworkspace\app\node_modules\gulp-sass\node_modules\nod
e-sass\lib\index.js:22:11)
at Object. (E:\ionicworkspace\app\node_modules\gulp-sass\node_mod
ules\node-sass\lib\index.js:188:23)
at Module._compile (module.js:434:26)
at Object.Module._extensions…js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (E:\ionicworkspace\app\node_modules\gulp-sass\index.js
:3:17)
at Module._compile (module.js:434:26)

This is a known issue which many people (also Ionic users) have come across, if you search for “libsass bindings not found” then you will see many discussion threads about it.

The best solution seems to be this answer:

Error running gulp sass

As you can see, the solution is that it works only with certain versions of nodejs. The problem is especially with “new” nodejs versions, e.g. nodejs v.4. I am using nodejs v.0.12 and I don’t have the problem.

Another discussion and possible solution is this post:

'libsass' bindings not found

So that is the issue. I’ve added a warning and some info to my README because I’ve seen many people struggling with this issue.

Other projects in my workspace is running.
Why this project only not running ?
I think, due to some version in compatabilities, i am getting these error.
I am using node 4.1.1. Do i need to downgrade to run this project ?

The reason is because the other projects are not using SASS … if you would execute “ionic setup sass” for those other projects, then you would see that they will have exactly the same problem.

Yes, if you have nodejs 4.1.1. (or any version of nodejs higher than 0.12.x) then it’s guaranteed that you will have this problem. Many people have reported this problem on the Ionic forum.

It would really be good if the Ionic Team would step in to warn Ionic users about this, but in the meantime I’ve added a warning to my starter app’s README, and I’ve written a page about the problem on my Wiki:

https://github.com/leob/ionic-quickstarter/wiki/ENOENT-and-libsass-bindings-not-found

So there you have it.

I have executed this command ionic setup sass in other projects. I am able to execute it successfully.

Then the package.json in those projects are specifying different versions of module dependencies (e.g. node-sass/lib-sass).

I’m 100% sure that the issue is with new Node.js versions which are breaking previous npm modules including libsass. The newer nodejs versions will likely need newer dependencies.

Can you try an “npm update” and let me know if that helps?

I have already executed this command npm update by seeing your second link.
But still i am getting the same error.

Okay then we can forget about that as a solution. I’ve got a report from someone else who had this problem and he went back to nodejs 0.12.x. I’m also staying on node.js 0.12.x, I’m hearing too many scary stories about node.js 4.x.

By the way would you be so kind to send me a package.json of another project that does work correctly with the new 4.x nodejs? If you want you can just paste the complete package.json in a message here.

That would be very helpful for other people who have this problem (this problem is in numerous threads on the Ionic Forum, it is all over the place).

{
“name”: “customsass”,
“version”: “1.0.0”,
“description”: “CustomSass: An Ionic project”,
“dependencies”: {
“gulp”: “^3.5.6”,
“gulp-sass”: “^2.0.4”,
“gulp-concat”: “^2.2.0”,
“gulp-minify-css”: “^0.3.0”,
“gulp-rename”: “^1.2.0”
},
“devDependencies”: {
“bower”: “^1.3.3”,
“gulp-util”: “^2.2.14”,
“shelljs”: “^0.3.0”
},
“cordovaPlugins”: [
“cordova-plugin-device”,
“cordova-plugin-console”,
“cordova-plugin-whitelist”,
“cordova-plugin-splashscreen”,
“cordova-plugin-statusbar”,
“ionic-plugin-keyboard”
],
“cordovaPlatforms”: [
“android”
]
}

Okay so I see that “gulp-sass” is way newer in this package,json ("^2.0.4") than in my starter’s package.json ("^1.3.3").

It then makes sense that with this newer nodejs you need the newer gulp-sass.

Try to change gulp-sass from “^1.3.3” to “^2.0.4” in the package.json and see if it works then.

Now i am getting the following error

ionic $ [16:05:42] Using gulpfile E:\ionicworkspace\app\gulpfile.js
[16:05:42] Starting ‘dev-config’…
[16:05:42] Finished ‘dev-config’ after 14 ms
[16:05:42] Starting ‘dev-sass’…
[16:05:42] Starting ‘inject-index’…
[16:05:42] Finished ‘inject-index’ after 3.01 ms
[16:05:42] Starting ‘watch’…
[16:05:42] Finished ‘watch’ after 30 ms
Error in plugin 'gulp-sass’
Message:
scss\ionic-customized.scss
12:3 file to import not found or unreadable: src/lib/ionic/scss/ionicons/ioni
cons.scss
Current dir: E:/ionicworkspace/app/scss/
Details:
column: 3
line: 12
file: E:/ionicworkspace/app/scss/ionic-customized.scss
status: 1
messageFormatted: scss\ionic-customized.scss
12:3 file to import not found or unreadable: src/lib/ionic/scss/ionicons/ioni
cons.scss
Current dir: E:/ionicworkspace/app/scss/
[16:05:42] Finished ‘dev-sass’ after 89 ms
[16:05:42] Starting ‘default’…
[16:05:42] Finished ‘default’ after 9.92 µs
[16:05:42] gulp-inject 36 files into index-template.html.
HTML changed: E:\ionicworkspace\app\src\index.html
JS changed: E:\ionicworkspace\app\src\js\config\config.js

In my browser blank page is comming.

Well the good news is that this change seems to have fixed the ‘libsass’ problem!

Now the error is this:

Message: scss\ionic-customized.scss 12:3 file to import not found or unreadable: src/lib/ionic/scss/ionicons/ionicons.scss

This could be my mistake somehow. Let me look at that.

I am also getting following errors in my browser console.
Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/ionic/js/ionic.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/ionic-service-core/ionic-core.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/ionic-service-analytics/ionic-analytics.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/parse/parse.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/firebase/firebase.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/angularfire/dist/angularfire.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/angular-resource/angular-resource.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/angular-messages/angular-messages.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/fus-messages/dist/fus-messages.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/angular-translate/angular-translate.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://192.168.2.89:8100/lib/ionic-content-banner/dist/ionic.content.banner.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
ng-img-crop.min.js:1 Uncaught ReferenceError: angular is not defined
http://192.168.2.89:8100/lib/ngCordova/dist/ng-cordova.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
36modules.js:23 Uncaught ReferenceError: angular is not defined
app.js:11 Uncaught ReferenceError: angular is not defined
application.ctrl.js:4 Uncaught ReferenceError: angular is not defined
application.service.js:4 Uncaught ReferenceError: angular is not defined
config.js:1 Uncaught ReferenceError: angular is not defined
templates.js:2 Uncaught ReferenceError: angular is not defined
http://192.168.2.89:8100/css/ionic.app.css Failed to load resource: the server responded with a status of 404 (Not Found)

Well, I’ve just installed gulp-sass 2.04 and now I get the same “file import not found or unreadable” error.

Apparently the new gulp-sass breaks stuff which worked before.

I’ll have a look.