我正在使用 angluarJS 开发 chrome 扩展,现在我遇到了一个完全烧毁我大脑的问题。
我想抓取数据,解析该数据并将解析后的数据存储在后台页面的 localStorage 中,并在浏览器操作中获取该数据并在弹出 html 中显示该数据。现在我想
反复抓取、解析和存储数据,如http://developer.chrome.com/extensions/alarms.html所述,我使用 chrome.alarms api 来执行此操作,但它无法正常工作。
这是我在后台控制器中的代码:
app.controller('bgCtrl', function AlfredCtrl($scope, courseService) {
var setLocal = function(){
console.log("fired inside setLocal(), but out of getCourses()");
courseService.getCourses().then(function (events){
console.log("fired inside of getCourses()");
localStorage.setItem("deadlines", JSON.stringify(events.deadlines));
})
};
var delay = 1 ;
chrome.alarms.create("scheduleRequest", {periodInMinutes: delay});
chrome.alarms.onAlarm.addListener(function(alarm){
if(alarm.name == "scheduleRequest"){
console.log("fired out of setLocal()");
setLocal();
}
});
});
函数 getCourses() 从 bg 中的服务返回。当它被调用时,它会返回解析后的数据。
当我在 chrome 开发工具中检查时,它会反复显示:
fired out of setLocal(). bgCtrl.js:32
fired inside setLocal(), but out of getCourses(). bgCtrl.js:7
也就是说函数 courseService.getCourses() 根本没有被调用。这就是我遇到的问题。
请帮我!!