当我们创建 Chrome 应用程序时,我们将脚本放在背景属性中清单.json file (这将用作应用程序的背景/事件页面)。我想要的是,我想使用 AngularJS后台脚本但我不知道怎么办。还有,这可能吗?我刚看到一些答案 https://stackoverflow.com/questions/26554366/angularjs-from-a-chrome-extension-background-script但它适用于 chrome 扩展。我尝试在 Chrome 应用程序中使用该解决方案,但没有成功。
--EDIT--
我所做的是,我从 manifest.json 文件中更改了一些内容
由此 ..
"app": {
"background": {
"scripts": ["assets/js/background.js"]
}
},
对此..
"app": {
"background": {
"page": "views/background.html"
}
},
and my 背景.html
<html ng-app="backgroundModule" ng-csp>
<head>
<meta charset="UTF-8">
<title>Background Page (point background property here to enable using of angular in background.js)</title>
</head>
<body>
<!-- JAVASCRIPT INCLUDES -->
<script src="../assets/js/vendor/angular1.2.min.js"></script>
<script src="../assets/background.js"></script>
</body>
</html>
and my 背景.js
var backgroundModule = angular.module('backgroundModule', []);
backgroundModule.run(function($rootScope, $http) {
$rootScope.domain = 'http://localhost/L&D/index.php';
console.log($rootScope.domain);
});
但我仍然遇到错误。它说
" Resource interpreted as Script but transferred with MIME type text/html: "chrome-extension://pdknlhegnpbgmbejpgjodmigodolofoi/views/background.html"