sideMenuController break in 0.9.25?

I’ve just tried updating my app to 0.9.25 (well, technically a couple commits after it, 02365e0fe35780e5629d44dea65dc51ceae2a075). To open the side menu, I’d made a directive:

	.directive('openMenu', ['$ionicGesture', '$rootScope', function($ionicGesture, $rootScope) {
	return {
		restrict: 'A',
		link: function ($scope, $element, $attrs) {
			var handleTap = function (e) {
				//console.log('openMenu');
				e.preventDefault();
				if ($rootScope.sideMenuController) {
					$rootScope.sideMenuController.toggleLeft();
				}
			};
			var tapGesture = $ionicGesture.on('tap', handleTap, $element);
			$scope.$on('$destroy', function () {
				// Clean up - unbind drag gesture handler
				$ionicGesture.off(tapGesture, 'tap', handleTap);
			});
		}
	};
}])

When it calls the toggle on the side menu controller, I get the following error:

Uncaught TypeError: Cannot call method 'enableAnimation' of undefined ionic.js:6598
ionic.controllers.SideMenuController.ionic.controllers.ViewController.inherit.toggleLeft ionic.js:6598
handleTap main.js:145
triggerEvent ionic.js:611
tapGesture ionic.js:1528
detect ionic.js:1210
bindDomOnTouch ionic.js:738

Am I supposed to be referencing that differently now?

I’m not sure what your goal is, but it looks like you’re doing it the hard way.

You can assign an ng-click directive to whatever element you want to use to open the menu (like <a ng-click="open_menu">Menu</a>, and then in your controller add a scope function to do the opening:

$scope.open_menu = function(){
    $scope.sideMenuController.toggleLeft();
};

I had this same issue and got the same error and what got me was the prefixing of directives:

<ion-side-menus>

	<fade-bar></fade-bar>

	<ion-pane ion-side-menu-content id="nav-menu-pane">

		<ion-nav-bar type="bar-positive" hide-back-button="true" animation="nav-title-slide-ios7"></ion-nav-bar>

		<ion-nav-view name="content"></ion-nav-view>
			
	</ion-pane>

	<ion-side-menu side="left">

		<div class="bar bar-header bar-dark">
			
			<h1 class="title">title</h1>
			
		</div>

		<ion-content has-header="true">

		</ion-content>

	</ion-side-menu>

</ion-side-menus>

I forgot to prefix the side-menu-content so Ionic didn’t recognize the directive.

2 Likes

Aha! Yeah, that’s it.

And I know ng-click can be registered, I was trying to make a directive at one point to make it easier to work around tap-through issue I was hitting. May not be necessary anymore but step one was just getting things updated to the latest version, since the release notes make me think you might have fixed my issue.

Yup, that worked, thanks @mhartington. I have to say, the ion- prefixes make sense for tags, but it makes it really confusing when upgrading my code that some attributes have ion- in front of them also, and some don’t. “Well, I need to add ion- to the side-menu-content= attribute, but not to the side= attribute on the ion-side-menu tag” and so on.

Hm, actually the docs still say: <pane side-menu-content> at http://ionicframework.com/docs/angularjs/controllers/side-menu/ even though it’s ion-side-menu-content.

@RangerRick I think they said in the announcement that they will be updating the documents to reflect this change once this version is released so expect the docs to be a little behind. The best place for up to date references is the ionic codepen page.

As far as some directives getting the ion- prefix and some not, I think that just maybe some confusion. The directives themselves are getting the prefix and the available options for the particular directive do not. Maybe making the directive’s options prefixed could help with the confusion, but it does seem a bit verbose in my opinion.

Any of the ionic guys want to way in on this?

Yeah, I understand that it’s a directive/option thing, it’s just a bit confusing when you’re mixing an attribute directive into another tag directive. In the long run, no one will have written it the old way and it won’t seem weird, I suppose, but just looking at the HTML I have to write, it feels very arbitrary even if there’s a reasonable technical reason for it.

Way down on the priority list, just thought I’d mention it. Might end up being confusing for n00bs. :smile: