出现以下错误- 堆栈:“ ReferenceError:未在$ eval上定义$ rootScope(在eval处为eval(在bootstrapAngular(http://localhost/app/login-logout.js:26:5)处为:1:1))在bootstrapAngular(http://localhost/app/login-logout.js:26:5)中是在Object.successCallback({{3} })↵在Object.setSuccess(http://localhost/app/login-logout.js:20:8)↵在XMLHttpRequest.req.onreadystatechange(http://localhost/js/keycloak.js:767:27)” 原始:错误
试图将$ rootScope注入run方法,但不起作用
'use strict';
(function () {
angular.module('KeycloakApp', ['ngCookies']);
initializeKeycloak();
function initializeKeycloak() {
var keycloakConfig = {
"url": "http://192.168.99.100:8080/auth",
"realm": "test",
"clientId": "bmui"
};
var keycloak = Keycloak(keycloakConfig);
keycloak.init({
onLoad: 'login-required'
}).success(function () {
keycloak.loadUserInfo().success(function (userInfo) {
bootstrapAngular(keycloak, userInfo);
});
});
}
function bootstrapAngular(keycloak, userInfo) {
angular.module('KeycloakApp')
.run(['$rootScope','$interval','$cookies', function ($rootScope,$interval,$cookies) {
var updateTokenInterval = $interval(function () {
// refresh token if it's valid for less then 15 minutes
keycloak.updateToken(15)
.success(function (refreshed) {
if (refreshed) {
$cookies.put('X-Authorization-Token', keycloak.token);
}
});
}, 10000);
$cookies.put('X-Authorization-Token', keycloak.token);
$rootScope.userLogout = function () {
$cookies.remove('X-Authorization-Token');
$interval.cancel(updateTokenInterval);
keycloak.logout();
};
$rootScope.authData = {};
$rootScope.authData.token = 'token';
$rootScope.authData.username = 'user data';
}]);
//angular.bootstrap(document, ['KeycloakApp']);
}
}());