Search code examples
angularjsangular-ui-routerangularjs-routingmeanjsngroute

How to get access to $route in meanjs controller


I am trying to get access to the current route since I added a title on it.

So the route looks something like

state('reports', {
    title: 'Reports',
    url: '/reports',
    templateUrl: 'modules/feeditems/views/reports.client.view.html'
}).

I want to get access to the title. so I can put it on my page Header. So in the Header controller I thought I could just get it off my

angular.module('core').controller('HeaderController', ['$rootScope', '$route', '$scope', 'Authentication', 'Menus',     
function($rootScope, $route, $scope, Authentication, Menus) {
        $scope.authentication = Authentication;         
        $scope.isCollapsed = false;
        $scope.menu = Menus.getMenu('topbar');
        $scope.$route = $route;
        console.log ('typeof($route) = ' + typeof($route));
        console.log ('typeof($route.current) = ' + typeof($route.current));

and I get the following error

Error: [$injector:unpr] Unknown provider: $routeProvider <- $route

so I add ngRoute

ApplicationConfiguration.registerModule('core', ['ngRoute']);

then I get the following error

Uncaught Error: [$injector:modulerr] Failed to instantiate module r2h due to: Error: [$injector:modulerr] Failed to instantiate module core due to: Error: [$injector:modulerr] Failed to instantiate module ngRoute due to: Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

How am I supposed to include this properly? the meanjs way?


Solution

  • I think you are confused, MeanJS standard configuration uses Angular UI Router

    For Angular UI Router

    You need to angular-ui-router.js then include ui.router inside your app dependency

    After that in configuration do register your state using $stateProvider

    Syntax

    app.config(function($stateProvider){
    
        $stateProvider.state('reports', {
            url: '/reports',
            templateUrl: 'modules/feeditems/views/reports.client.view.html'
        })
    
    })
    

    For adding title dynamically you could refer this SO Answer