0

Hi i am getting 'ReferenceError: $ is not defined' in my code. This is my sample code

$rootScope.$on('$stateChangeStart', function (event, next, current) {
        // redirect to login page if not logged in and trying to access a restricted page
        var restrictedPage = $.inArray($state.current.name, ['login']) === -1;
        var loggedIn = $rootScope.globals.currentUser;
        if (restrictedPage && !loggedIn) {
            $state.go('login');
        }
    });

This code am writing inside run();

3
  • 2
    That means jquery not defined,check whether u called the jquery library properly!! Commented Aug 1, 2016 at 10:57
  • Did you include a script for jQuery? Commented Aug 1, 2016 at 10:58
  • When i pass the jquery reference through CDN its working, but when did same by bundle.js using require('jquery/dist/jquery.js'); its not working. @Lokesh_Ram Commented Aug 1, 2016 at 11:52

2 Answers 2

5

Add jquery file in your project. $ means jQuery.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

2

If you're using a NodeJS project, you can install jquery, then import the jquery library. e.g.

Console: (run from project root) npm install jquery

Javascript: (insert in header of your .js file) var $ = require('jquery');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.