The menu is located outside a <div> block which is rendered via UI Router's ui-view.
In order to modify the menu according to the state parameters, I need access to the current state parameters from within the menu's controller, but the $stateParams variable is an empty object when used outside the ui-view part.
How can I access them?
angular.module('myapp').controller('MenuCtrl', ['$scope', '$rootScope', '$stateParams', '$meteor', '$filter',
function($scope, $rootScope, $stateParams, $meteor, $filter) {
// ... $stateParams equals {}
}
]);
Try to watch for state changes in your controller...
angular.module('myapp').controller('MenuCtrl', ['$scope', '$rootScope', '$meteor', '$filter',
function($scope, $rootScope, $meteor, $filter) {
//this watches for state changes
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
//do something when state changes
state = toState.name;
postid = toParams.postid;
console.log(toParams); //this is the stateParams you need
});
}
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With