我尝试在next
中检查下一个令牌,但我收到了错误:
TypeError: next.localStorage is not a function
APP.JS
.run(function ($rootScope, $location,$log,User) {
$rootScope.$on("$locationChangeStart", function (event,next, current,jwtHelper) {
if(next.localStorage("id_token")){
console.log("true");
}else{
console.log("false");
}
/*
});
答案 0 :(得分:0)
AngularJS文档将第二个参数“newUrl”显示为字符串。
https://docs.angularjs.org/api/ng/service/ $位置
angularEvent :对象。合成事件对象。
newUrl :字符串。新网址
oldUrl :string(可选)。之前的网址已被更改。
newState :字符串(可选)。新的历史状态对象
oldState :字符串(可选)。历史状态对象就在它之前 改变了。
您的代码正在尝试执行以下操作:
document.querySelector('button#start').onclick = function()
{
var counter;
var count = 60;
var mod = 0;
var min = 0;
var finalCount;
//var correct = new Audio('sound/tone-beep.mp3');
//var wrong = new Audio('sound/wrong-action.mp3');
this.style.display = "none";
function countDown()
{ mod = count % 60;
if ( mod == 0 )
{ min = count / 60;
document.getElementById('timer').innerHTML = min+':00';
}
else
{
min = count/ 60;
sec = count % 60;
min = Math.floor(min);
document.getElementById('timer').innerHTML = (sec < 10)? min+':0'+sec : min+':'+sec;
}
count -=1;
if( count < 0)
{ clearInterval(counter);
counter = 0;
count = 0;
document.getElementById('timer').innerHTML = '0:00';
document.querySelector('button#start').style.display = "block";
if(document.getElementById('final-score'))
{
var score = document.getElementById('score').innerHTML;
var p = document.createElement('p');
p.innerHTML = score;
document.getElementById('ex1').appendChild(p);
}
else
{
var elem = document.createElement('h3');
elem.setAttribute("id","final-score")
elem.appendChild(document.createTextNode('The Final Score'));
document.getElementById('ex1').appendChild(elem);
elem = document.createElement('p');
var score = document.getElementById('score').innerHTML;
elem.appendChild(document.createTextNode(score));
document.getElementById('ex1').appendChild(elem);
}
document.getElementById('score').innerHTML = 0;
console.log(counter);
}
return count;
}
counter = setInterval(countDown, 1000);
function mathP()
{
var par = Math.round(Math.random()*(5-2)+2);
var arr = [];
var results = [];
var text, oper, ran, num;
num = 0;
function value(operator,number,total)
{ if ( operator == "+")
{
return total+number;
}
else{
return total-number;
}
}
for(var i=0; i < par; i++)
{
oper = Math.round(Math.random()*(2-1)+1);
oper = (oper == 1)? '+' : '-';
ran = Math.round(Math.random()*(10-1)+1);
if ( i == 0 && oper == '+')
{
arr[i] = ran;
}
else
{
arr[i] = ' '+oper+' '+ran;
}
num = value(oper,ran,num);
if(i < 1)
{text = arr[i]
}
else{
text += arr[i];
}
}
document.querySelector('h4').innerHTML = text;
results[0] = num;
results[1] = par;
return results;
}// function mathP
var globalNum;
globalNum = mathP();
document.querySelector('button#positive').onclick = function(){
if (count > 0)
{
var a = document.getElementById('score');
if (globalNum[0] > 0)
{
a.innerHTML= globalNum[1] + parseInt(a.innerHTML);
//correct.play();
console.log('You were right the value was '+globalNum[0]+' so you get '+globalNum[1]+' points');
}
else
{
a.innerHTML= parseInt(a.innerHTML) - globalNum[1] ;
//wrong.play();
console.log('You were wrong the value was '+globalNum[0]+' so you get -'+globalNum[1]+' points');
}
globalNum = mathP();
}
};
document.querySelector('button#negative').onclick = function(){
if (count > 0)
{
var a = document.getElementById('score');
if (globalNum[0] < 0)
{
a.innerHTML = globalNum[1]+ parseInt(a.innerHTML);
// correct.play();
console.log('You were right the value was '+globalNum[0]+' so you get '+globalNum[1]+' points');
}
else
{
a.innerHTML= parseInt(a.innerHTML) - globalNum[1];
// wrong.play();
console.log('You were wrong the value was '+globalNum[0]+' so you get -'+globalNum[1]+' points');
}
globalNum = mathP();
}
};
}// button#start onclick
localStorage是一个窗口对象,应该在所有页面之间共享,以便您可以通过以下方式访问它:
if("http://www.app.com/path".localStorage("id_token")){