【问题标题】:Angular html template inside a directive won't render指令中的 Angular html 模板不会呈现
【发布时间】:2017-05-17 20:13:03
【问题描述】:

我知道这个问题有类似的问题得到解答,但没有一个解决方案对我有用。我有以下文件夹结构:

static
----calendar
--------calendar.controller.js
--------calendar.view.html
----home
--------home.controller.js
--------home.view.html
----app.js
----index.html

在 calendar.controller.js 中,我为我的日历创建了一个指令,如下所示:

.directive('myCalendar',function(){
        return{
            restrict:'E',
            template:"calendar.view.html"
        }
    })

我正在尝试从 home.view.html 渲染该日历模板,但没有成功。

我的 home.view.html 中有这个:

<my-calendar></my-calendar>

在浏览器上它实际上显示了我试图让他绑定的路径(在浏览器上你可以看到“./calendar/calendar.view.html”)。我已经尝试以多种方式更改指令的路径:

 - template:"./calendar.view.html"
 - template:"/calendar.view.html"
 - template:"./calendar/calendar.view.html"
 - template:"/calendar/calendar.view.html"

...但它仍然无法正常工作。谢谢。

【问题讨论】:

  • 试试templateUrl而不是template
  • - 完美!!非常感谢;)

标签: html angularjs templates bind directive


【解决方案1】:
 template:"calendar.view.html"

这是一个错误 你需要 templateUrl:"calendar.view.html" 而是

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 2015-07-05
    相关资源
    最近更新 更多