【发布时间】:2016-09-04 17:10:17
【问题描述】:
我为我的 Angular 应用程序创建了一个指令,在该指令中我使用 templateUrl 来获取模板。
templateUrl: 'templates/searchbox-template.html',
这在我的本地服务器上运行良好,但是当我将它托管在 firebase 上时,它会反复发出此警告-
WARNING: Tried to load angular more than once
页面也陷入循环,重复地将 index.html 添加到页面。 如果您从导航栏中转到我使用该指令的公司或工作选项卡,您可以看到应用程序here。 我无法弄清楚应该使用什么路径来阻止这种情况。这是应用程序的结构 -
.
├── app
│ ├── 404.html
│ ├── favicon.ico
│ ├── images
│ ├── index.html
│ ├── robots.txt
│ ├── scripts
│ ├── styles
│ ├── templates
│ └── views
├── bower_components
│ ├── angular
│ ├── angular-mocks
│ ├── angular-route
│ ├── animate.css
│ ├── bootstrap
│ ├── jquery
│ └── jssocials
├── bower.json
├── dist
│ ├── 404.html
│ ├── favicon.ico
│ ├── fonts
│ ├── index.html
│ ├── robots.txt
│ ├── scripts
│ └── styles
├── firebase.json
.
├── app
│ ├── 404.html
│ ├── favicon.ico
│ ├── images
│ ├── index.html
│ ├── robots.txt
│ ├── scripts
│ │ ├── app.js
│ │ ├── controllers
│ │ ├── directives
│ │ └── services
│ ├── styles
│ │ └── main.css
│ ├── templates
│ │ └── searchbox-template.html
│ └── views
│ ├── about.html
│ ├── companiesall.html
│ ├── company.html
│ ├── contact.html
│ ├── jobsall.html
│ └── main.html
如您所见,我的模板位于模板文件夹中。请帮我解决一下这个。谢谢。
更新 - 根据answer ,该指令无法找到模板,因此一次又一次地加载 index.html -
.otherwise({
redirectTo: '/'
});
我只需要找出模板的正确路径。
这是 firebase.json json 文件的内容 -
{
"hosting": {
"public": "dist",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
【问题讨论】:
-
该模板是否包含 ng-app 指令?如果您已经在主模板中添加了 ng-app,则可能会出现该消息,然后尝试加载另一个包含 ng-app 的模板。
-
不,ng-app 只在 index.html 文件中。
-
取决于您的服务器配置,但如果
'/'在您的根目录中引用index.html,那么我想正确的路径是'/templates/searchbox-template.html' -
我试过了,不行。
-
'/'是否映射到视图main.html?如果是这样,听起来您的服务器仅在views目录下静态提供文件,并且不允许访问templates目录。要对其进行测试,请尝试从templates获取模板并将其放在views下,然后相应地更改templateUrl。
标签: javascript angularjs angularjs-directive