gpt4 book ai didi

javascript - 无法在 angularjs 中加载模板

转载 作者:行者123 更新时间:2023-11-28 05:55:30 24 4
gpt4 key购买 nike

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

  • 应用程序

    • 常见

      • js

        • 指令

          通知.js

        • 模板

          通知.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 cannot load 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

最佳答案

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

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

关于javascript - 无法在 angularjs 中加载模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37723987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com