我有一个AngularJS应用程序。在该应用程序中,我尝试使用自定义指令加载一段HTML。我的指令(在app.js中)如下:
app.directive('mytable', function() {
return {
restrict: 'E',
templateUrl: '/mytable'
};
});然后,在我的超文本标记语言文件(index.html)中,我只指定了定制标记。
<mytable></mytable>mytable.html中的实现细节只是静态超文本标记语言。在Java Play的路由方面,我有:
GET /mytable Application.mytable在我的播放控制器(Application.java)中,我有:
public static void mytable() { render(); }然而,当我尝试加载一个页面时,我得到:
GET http://localhost:9000/mytable 500 (Internal Server Error)
XHR finished loading: GET "http://localhost:9000/mytable".经过仔细检查,在控制台中,我看到:
Template not found
The template Application/mytable.txt does not exist.我如何修复我的代码?当我在Application.java中的所有其他控制器都是相同的,并且正确地呈现.html文件时,为什么它要尝试呈现mytable.txt而不是mytable.html?
顺便说一句:http://localhost:9000/mytable确实正确地为<mytable>呈现了静态内容。
发布于 2015-07-01 23:04:14
编辑:这只适用于播放版本2.x
我有一种感觉,你的控制器的方法有点错误。我会重写这段代码
public static void mytable() { render(); }至:
public static Result mytable() {
ok(index.render());
}其中index是您的视图,render是您调用以呈现此视图的方法,并且您的控制器返回一个Result (通过ok()方法)
https://stackoverflow.com/questions/31164744
复制相似问题