Parsa
Parsa

Reputation: 3236

Open Side Menu Default On Condition

Working with the Ionic Framework, I would like to open the side menu by default on condition that a specific variable is not null.

My current method is as follows:

$ionicPlatform.ready(function() {
    if (User.pref == null) {
        $ionicSideMenuDelegate.toggleLeft([true]);
    }
});

I believe this doesn't work as the conditional is firing off before the menu is loaded (but after the 'platform' is ready).

EDIT:

The full code is here, using an alert statement I can indeed verify that the nested code is being executed.

.controller('AppCtrl', function($scope, $ionicSideMenuDelegate, $ionicPlatform, Colleges, User) {
  $ionicPlatform.ready(function() {
  if (User.pref == null) {
    alert('it is closed by default ' + $ionicSideMenuDelegate.isOpen());
    // output: it is null udefined
    $ionicSideMenuDelegate.toggleLeft([true]);
    alert('it should be open ' + $ionicSideMenuDelegate.isOpen());
    // output: it should be open undefined
  }
  });
})

Upvotes: 0

Views: 178

Answers (1)

caraie
caraie

Reputation: 1104

try calling $ionicSideMenuDelegate.toggleLeft(); using a $timeout of 0.

Upvotes: 1

Related Questions