Chrome扩展程序在加载同步数据后运行角度

时间:2015-04-19 15:59:31

标签: javascript angularjs google-chrome google-chrome-extension google-chrome-storage

如何从chrome.storage获取数据后运行angularjs引擎?

我在app.js中有这段代码:

'use strict';

var host = '';
var port = '';
chrome.storage.sync.get({
    host: '',
    port: '',
}, function(items) {
    host = items.host;
    port = items.port;
});
// need to run this line after data is retrived from chrome.storage
var app = angular.module('TouchApp', ['TouchApp.services', 'TouchApp.controllers', 'TouchApp.directives']); 

chrome获取数据后,运行angularjs引擎。

任何解决方案?

1 个答案:

答案 0 :(得分:1)

回调的目的是在异步功能完成后运行。所以你需要把代码放在那里。

var app;

chrome.storage.sync.get({
    host: '',
    port: '',
}, function(items) {
    host = items.host;
    port = items.port;
    app = angular.module('TouchApp', ['TouchApp.services', 'TouchApp.controllers', 'TouchApp.directives']);
});