ReferenceError:在Angular JS中未定义$

Kis*_*han 0 jquery angularjs

嗨,我在我的代码中收到“ ReferenceError:$未定义”。这是我的示例代码

$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');
        }
    });
Run Code Online (Sandbox Code Playgroud)

这段代码是在run()中编写的;

Dur*_*ngh 5

在您的项目中添加jquery文件。$表示jQuery。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
Run Code Online (Sandbox Code Playgroud)