Javascript 无法在angularjs中加载模板

Javascript 无法在angularjs中加载模板,javascript,angularjs,Javascript,Angularjs,在angulajs 1x应用程序中,我有以下结构 应用程序 普通的 js 指令 通知.js (function(module) { var notifications = function(notificating) { return { restrict: "AE", templateUrl: "templates/notifications.html", // tried also templateU

在angulajs 1x应用程序中,我有以下结构

  • 应用程序

    • 普通的

      • js

        • 指令

          通知.js

        • (function(module) {    
              var notifications = function(notificating) {
                  return {
                      restrict: "AE",
                      templateUrl: "templates/notifications.html",
          // tried also   templateUrl: "../templates/notifications.html",
          // tried also   templateUrl: "app/common/templates/notifications.html",
                          link: function(scope) {
                          // todo
                      }
                  };
              };    
              module.directive("notifications", notifications);
          }(angular.module("common")));
          
        • 模板

          notifications.html

    • 保安

通知.js

(function(module) {    
    var notifications = function(notificating) {
        return {
            restrict: "AE",
            templateUrl: "templates/notifications.html",
// tried also   templateUrl: "../templates/notifications.html",
// tried also   templateUrl: "app/common/templates/notifications.html",
                link: function(scope) {
                // todo
            }
        };
    };    
    module.directive("notifications", notifications);
}(angular.module("common")));
在firebug控制台中,我得到以下错误

angular.js:9658 XMLHttpRequest无法加载 file:///G:/My%20App/app/templates/notifications.html. 交叉起源 请求仅支持协议方案:http、数据、chrome、, chrome扩展、https、chrome扩展资源。(匿名) 函数)@angular.js:9658sendReq@angular.js:9462serverRequest@ angular.js:9179processQueue@angular.js:12914(匿名函数)@ angular.js:12930$eval@angular.js:14123$digest@ angular.js:13939$apply@angular.js:14227bootstrapApply@ angular.js:1487invoke@angular.js:4152DobotStrap@ angular.js:1485bootstrap@angular.js:1505angularInit@ angular.js:1399(匿名函数)@angular.js:25579trigger@ angular.js:2742eventHandler@angular.js:3013 angular.js:11358错误: [$compile:tpload]无法加载模板:templates/templates.html $compile/tpload?p0=模板%2Ftemplates.html


如果您给出的目录结构正确,那么下面的目录结构应该可以工作

templateUrl: "common/js/templates/notifications.html",

如果您给出的目录结构正确,那么下面的目录结构应该可以工作

templateUrl: "common/js/templates/notifications.html",

必须从index.html开始创建路径


所以“common/js/templates/notifications.html”应该可以工作。

您必须从index.html开始路径

templateUrl: "common/js/templates/notifications.html",

所以“common/js/templates/notifications.html”应该可以使用。

您必须在某些服务器上运行此应用程序。当前您正在直接运行以访问该文件。您可以在此处获得浏览器同步的帮助。您必须在某些服务器上运行此应用程序。当前您正在直接运行以访问该文件。您可以在此处获得浏览器同步的帮助。
templateUrl: "common/js/templates/notifications.html",