从Chrome扩展的背景剧本AngularJS [英] AngularJS from a Chrome Extension background script
问题描述
由于角是联系在一起的观点,并在主视图扩展自举,我想简单的答案是不,不可能的,但希望确认,因为我无法找到一个明确的答案的任何地方。
Given that Angular is tied to the views and bootstrapped in the main extension view, I assume the simple answer is "No, not possible", but wanted to confirm as I can't find a definitive answer anywhere.
我的用例是,当发现扩展名是轮询从API更新的内容,更新和扩展的徽章;我很想能够从延伸的角度codeBase的重新使用我的API服务。
My use case is that the extension will be polling for updated content from an API, and updating the extension's badge when found; I'd love to be able to re-use my API service from the extension's Angular codebase.
如果不可能的,张角和背景之间的脚本共享code任何建议的解决办法?
If not possible, any suggested workarounds for sharing code between the Angular extension and the background script?
推荐答案
感谢您的输入@Xan,@harish - 根据您的反馈做了一些更多的调查,并有解决方案。在本质上,而不是指向在Chrome清单的背景剧本,我指着后台HTML页面,然后我用它来引导我的角度应用程序。该培训相关code:
Thanks for the input @Xan, @harish - based on your feedback did some more investigation and have the solution. In essence, instead of pointing to a background script in the Chrome manifest, I am pointing to a background HTML page, which I then use to bootstrap my Angular app. The relevent code:
manifest.json的:
manifest.json:
...
"background": {
"page": "/app/background.html"
}
...
background.html
<!DOCTYPE html>
<html lang="en" ng-app="MyApp" ng-csp>
<head>
<title>Background Page</title>
<meta charset="UTF-8">
<script type="text/javascript"
src="/app/components/angular/angular.js"></script>
<script type="text/javascript"
src="/app/scripts/background.js"></script>
</head>
<body></body>
</html>
background.js
var app = angular.module('MyApp', []);
app.run(function() {
console.log('Hello world');
});
这篇关于从Chrome扩展的背景剧本AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!