javascript - angularJs 指令中 templateUrl 的正确路径应该是什么?

标签 javascript angularjs angularjs-directive

我想将 templateUrl 的路径作为单独的 .jade 文件给出。但它显示 500 errError: [$compile:tpload]

下面是我的指令中的代码

app.directive('personRecord',['$http',function(http){
    return{
        restrict : 'AE',
        templateUrl : '../../views/template.jade',
        link : function(scope,ele,attr){

        }
    }
}]);

我的文件夹结构如下所示。

bin
node_modules
public
|-- js
    |-- main.js
routes
views
|-- template.jade
|-- index.jade
app.js
package.json

请帮我解决这个问题!我在这里缺少什么!

最佳答案

我的建议是将 View 文件夹放在公共(public)文件夹中:-

bin
node_modules
public
|-- js
|    |-- main.js
|--views
    |-- template.jade
    |-- index.jade
routes
app.js
package.json

然后使用

app.directive('personRecord', function(http){
    return {
        restrict : 'AE',
        templateUrl : 'views/template.jade',
        link : function(scope, ele, attr){

        }
    };
});

希望有帮助:)

关于javascript - angularJs 指令中 templateUrl 的正确路径应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30952600/

相关文章:

javascript - AngularJs "on"事件监听器接收到 "broadcast"乱序发送的事件

javascript - 当 jQuery sortable 发生更改/更新时收到通知

javascript - jQuery 点击功能——选择器的 css 没有被改变

javascript - 关于下拉菜单

javascript - addEventListener 不适用于基于 IE 11 的客户端基础应用程序

angularjs - 条件 anchor 标签和点击

javascript - 如何在 localStorage 中存储对象数组?

angularjs - Jasmine /Angular : TypeError: Cannot read property '$modules/$injector' of undefined

javascript - Angularjs 指令附加 $http 请求

javascript - 一起使用隔离范围和嵌入式指令 Controller