簡體   English   中英

chrome擴展角度js范圍不起作用?

[英]chrome extension angular js scope not working?

嗨,我正在嘗試創建一個使用angular的簡單chrome擴展,但是我對為什么示波器不起作用感到困惑。

這是我的manifest.json

{
  "manifest_version": 2,

  "name": "Getting started example",
  "description": "This extension shows a Google Image search result for the current page",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html",
    "default_title": "Test"
  },
  "content_scripts": [
    {
      "matches" : [ "<all_urls>" ],
      "js" : [
        "/js/lib/angular.min.js", "/js/lib/jquery-1.8.2.min.js", "/js/angularInit.js"
      ],
      "css" : [
        "/css/background.css"
      ],
      "all_frames" : true
    }
  ],
  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}

這是我初始化模塊和控制器的地方

var curMod = angular.module('CurMod', []);
curMod.controller("curController", ['$scope', function($scope) {
    $scope.message = "JDF";
}]);

這是我的popup.html:

<!doctype html>
<!--
 This page is shown when the extension button is clicked, because the
 "browser_action" field in manifest.json contains the "default_popup" key with
 value "popup.html".
 -->
<html ng-app="CurMod" ng-csp>
  <head>
    <title>Getting Started Extension's Popup</title>
    <style>
      body {
        font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
        font-size: 100%;
      }
      #status {
        /* avoid an excessively wide status text */
        white-space: pre;
        text-overflow: ellipsis;
        overflow: hidden;
        max-width: 400px;
      }
    </style>

    <!--
      - JavaScript and HTML must be in separate files: see our Content Security
      - Policy documentation[1] for details and explanation.
      -
      - [1]: https://developer.chrome.com/extensions/contentSecurityPolicy
     -->
    <script src="popup.js"></script>
  </head>
  <body>
    <div ng-controller="curController">
      {{message}}
    </div>
    <div id="status"></div>
    <img id="image-result" hidden>
  </body>
</html>

似乎{{message}}從未填充,即使我在curController的angularInit.js中進行了設置。

我需要做其他任何設置才能在chrome擴展程序中工作嗎?

謝謝

好吧,您的彈出窗口中沒有Angular!

內容腳本不會注入您自己的頁面中。

您需要將<script>標記添加到popup.html本身。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM