Kishan
Kishan

Reputation: 388

ReferenceError: $ is not defined in Angular JS

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();

Upvotes: 0

Views: 22128

Answers (2)

Nick Grealy
Nick Grealy

Reputation: 25942

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');

Upvotes: 2

Durgpal Singh
Durgpal Singh

Reputation: 11983

Add jquery file in your project. $ means jQuery.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>

Upvotes: 5

Related Questions