【问题标题】:Angular directive inside Play Framework applicationPlay Framework 应用程序中的 Angular 指令
【发布时间】:2015-11-23 01:02:57
【问题描述】:

我正在现有的 Play Framework 2.0 应用程序中添加一些 angularJs 函数。

angularjs 文件在public/ 文件夹中提供。一切正常,直到我尝试使用带有分离模板的指令:

指令jsmulti-charts.js和指令模板multi-charts.html都放在同一个目录components/directives。 所以文件的完整路径是:

  • public/components/directives/multi-charts.js
  • public/components/directives/multi-charts.html

问题是我无法使用templateUrl 访问指令内的模板文件。

指令:

app.directive('multiCharts', ['chartService', function(chartService){
    return {
        restrict: 'EACM',
        templateUrl: 'components/directives/multi-charts.html',
        replace: true,
        link: function (scope, elem, attrs) {
        }
    }}]);

无法实现模板运行应用程序:

GET http://localhost:9000/company/components/directives/multi-chart.html 404 (Not Found)

更改templateUrl 内的路径不会改变错误。

我遗漏了一些东西,有没有办法在内部 Play Framework 网络服务器提供的指令中引用 html 模板?

【问题讨论】:

  • multi-charts.html != multi-chart.html 您缺少 s 还是只是示例中的拼写错误?

标签: angularjs angularjs-directive playframework playframework-2.0


【解决方案1】:

找到了解决方案。 添加新路由到播放框架routes文件:

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file                               controllers.Assets.at(path="/public", file)

我可以通过以下方式访问模板:

templateUrl: '../assets/js/angular/directives/multi-charts.html'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多