Skip to content

ReferenceError #3

Description

@datachand

Hi,

I have a problem with underscore, can u explain?

Console shows me

ReferenceError: _ is not defined
    at routeClean (http://127.0.0.1:18181/assets/javascripts/app/routes.js?v=0.1:25:20)
    at http://127.0.0.1:18181/assets/javascripts/app/routes.js?v=0.1:34:17
    at h.$broadcast (http://127.0.0.1:18181/assets/javascripts/app/libraries/angular/angular.min.js?v=0.1:113:360)
    at Object.v.transitionTo (http://127.0.0.1:18181/assets/javascripts/app/libraries/vendor/angularui/angular-ui-router.min.js?v=0.1:7:9719)
    at Array.<anonymous> (http://127.0.0.1:18181/assets/javascripts/app/libraries/vendor/angularui/angular-ui-router.min.js?v=0.1:7:6815)
    at Object.d [as invoke] (http://127.0.0.1:18181/assets/javascripts/app/libraries/angular/angular.min.js?v=0.1:34:479)
    at d (http://127.0.0.1:18181/assets/javascripts/app/libraries/vendor/angularui/angular-ui-router.min.js?v=0.1:7:4447)
    at http://127.0.0.1:18181/assets/javascripts/app/libraries/vendor/angularui/angular-ui-router.min.js?v=0.1:7:4996
    at d (http://127.0.0.1:18181/assets/javascripts/app/libraries/vendor/angularui/angular-ui-router.min.js?v=0.1:7:5539)
    at d (http://127.0.0.1:18181/assets/javascripts/app/libraries/vendor/angularui/angular-ui-router.min.js?v=0.1:7:5652) 

routes.min.js is:

'use strict';

define([
    'app/app',
    'app/controllers/home',
    'app/controllers/login',
    'app/services/authentication',
    'app/services/authorisation',
    'app/services/session'
], function(app) {

    app.run(['$rootScope', '$http' ,'$location', '$state', 'AuthenticationService', 'AuthorisationService', 'SessionService',  function ($rootScope,
        $http, $location, $state, authentication, authorisation, session) {

        var NoAuthorisationRequiredRoute = ['/login'];
        var AdminRoute = ['/admin'];

        var routeClean = function(route) {
            return _.find(NoAuthorisationRequiredRoute, function(noAuthRoute){
                return _.str.startsWith(route, noAuthRoute);
            });
        }

        var routeClean = function(route) {
            return _.find(AdminRoute, function(noAuthRoute){
                return _.str.startsWith(route, noAuthRoute);
            });
        }

        $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams, toParams, fromState, fromParams){
            $rootScope.toState = toState;
            $rootScope.toStateParams = toStateParams;

            if(!routeClean($location.url()) && !authentication.isLoggedIn()) {
                event.preventDefault();
                $state.go('/login');
            } else if(AdminRoute($location.url()) && !authorisation.validateRoleAdmin(session.currentUser)) {
                event.preventDefault();
                $state.go('/error')
            }

        });

        $rootScope.$on('$stateChangeSuccess', function(currentRoute, previousRoute) {
            $rootScope.title = $state.current.title;
        });

        $rootScope.$on('$stateNotFound',
            function(event, unfoundState, fromState, fromParams){
                console.log(unfoundState.to); // "lazy.state"
                console.log(unfoundState.toParams); // {a:1, b:2}
                console.log(unfoundState.options); // {inherit:false} + default options
        });

    }]);

    app.config(['$locationProvider', '$stateProvider','$urlRouterProvider', '$httpProvider', function($locationProvider, $stateProvider, $urlRouterProvider, $httpProvider) {


        $stateProvider.state('home', {
            url: '/',
            controller: 'HomeController',
            templateUrl: '/assets/javascripts/app/partials/home.html',
            title: 'Dashboard',
            authenticate: true
        });

        $stateProvider.state('login', {
            url: '/login',
            controller: 'LoginController',
            templateUrl: '/assets/javascripts/app/partials/login.html',
            title: 'Login',
            authenticate: false
        });

        $locationProvider.html5Mode(true);

        $httpProvider.interceptors.push(function($q, $location) {
            return {
                'responseError': function(response) {
                    if(response.status === 401 || response.status === 403) {
                        $location.path('/login');
                    }
                    return $q.reject(response);
                }
            };
        });
    }]);



    return app;

});

I have used require module loader, should i add underscore.js?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions