私はangluarJSを使用してクロム拡張に取り組んでいます.今、私は完全に頭を悩ませる問題を抱えています.
データを取得し、そのデータを解析し、解析したデータをバックグラウンド ページの 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 のサービスから返されます。呼び出されると、解析されたデータが返されます。
クロム開発ツールで調べると、繰り返し表示されます:
fired out of setLocal(). bgCtrl.js:32
fired inside setLocal(), but out of getCourses(). bgCtrl.js:7
つまり、関数 courseService.getCourses() はまったく callec されていませんでした。それが私の問題です。
私を助けてください!!