【问题标题】:What file path would I use with ng-include?我将在 ng-include 中使用什么文件路径?
【发布时间】:2015-02-25 01:42:52
【问题描述】:

我的angular项目的路径是这样的

web
    server.py ##flask server program
    app
        static
            app.js
            controllers.js
            etc...
        templates
            index.html
            home.html

index.html

<!-- this didn't work -->
<ng-include src="templates/home.html"><ng-include>

<!-- nor did this -->
<ng-include src="home.html"></ng-include>

home.html

<h1> home! </h1>

除了我在输出中没有看到部分 (home.html)。

有人看到我的错误吗?

【问题讨论】:

  • 您没有传递文件路径。您传递要包含的部分的 URL。就像您在&lt;a href="..."&gt;&lt;img src="..."&gt; 中一样。因此,请查看地址栏中的 URL,并使用相对或(更好的)绝对路径指向要加载的部分。
  • "使用相对路径或(更好的)绝对路径" > 为什么使用绝对路径会更好?对我来说,看起来我们并不完全确定那里发生了什么。我想使用相对路径应该更好,因为它更可重用。

标签: html angularjs filepath partials angularjs-ng-include


【解决方案1】:

ng-include 的 src 属性需要一个字符串。要么传递作用域变量,要么直接传递字符串。

<ng-include src=" 'templates/home.html' "></ng-include>

【讨论】:

    猜你喜欢
    • 2010-12-29
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2013-02-25
    • 2016-12-20
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    相关资源
    最近更新 更多