简体   繁体   English

无法在 angularjs 中加载模板

[英]Failed to load template in angularjs

Inside angulajs 1x app I have following structure在 angulajs 1x 应用程序中,我具有以下结构

  • app应用程序

    • common常见的

      • js js

        • directives指令

          notifications.js通知.js

        • templates模板

          notifications.html通知.html

    • security安全

notifications.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")));

inside firebug console I'm getting following error在萤火虫控制台内我收到以下错误

angular.js:9658 XMLHttpRequest cannot load file:///G:/My%20App/app/templates/notifications.html. angular.js:9658 XMLHttpRequest 无法加载 file:///G:/My%20App/app/templates/notifications.html。 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.(anonymous function) @ angular.js:9658sendReq @ angular.js:9462serverRequest @ angular.js:9179processQueue @ angular.js:12914(anonymous function) @ angular.js:12930$eval @ angular.js:14123$digest @ angular.js:13939$apply @ angular.js:14227bootstrapApply @ angular.js:1487invoke @ angular.js:4152doBootstrap @ angular.js:1485bootstrap @ angular.js:1505angularInit @ angular.js:1399(anonymous function) @ angular.js:25579trigger @ angular.js:2742eventHandler @ angular.js:3013 angular.js:11358 Error: [$compile:tpload] Failed to load template: templates/templates.html http://errors.angularjs.org/1.3.0/ $compile/tpload?p0=templates%2Ftemplates.html跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。(匿名函数)@ 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 :4152doBootstrap @ 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 http://errors.angularjs.org/1.3.0/ $compile/tpload?p0=templates%2Ftemplates.html

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

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

You have to start the path from the index.html.您必须从 index.html 开始路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM