我尝试使用如下自定义布局将 Angular JS 应用程序集成到 vaadin 中:
VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setMargin(true);
mainLayout.setWidth("1380px");
setCompositionRoot(mainLayout);
Panel panel = new Panel();
CustomLayout layout = null;
try {
String dynamicHtml = "<div ng-app=\"app\">..........</div>";
layout =
new CustomLayout(new ByteArrayInputStream(dynamicHtml.getBytes()));
} catch (IOException e) {
logger.error("could not create custom layaout", e);
}
panel.setContent(layout);
mainLayout.addComponent(panel);
importJs();
public void importJs() {
String PATH_TO_JS_SCRIPT = jsURL+"?tata=" + new Date();
String script = "try{var fileref=document.createElement('script');";
script += "fileref.setAttribute(\"type\",\"text/javascript\");";
script += "fileref.setAttribute(\"src\", \"" + PATH_TO_JS_SCRIPT +
"\");";
script += "document.getElementsByTagName(\"head
\")[0].appendChild(fileref);}catch(e){alert(e);}";
Page.getCurrent().getJavaScript().execute(script);
}
我使用 importJs 方法导入脚本 js。 我第一次访问该页面时,js 文件被加载并且可以工作。 第二次就不行了。 就好像脚本没有导入一样。 我不明白我的代码有什么问题? 使用 Javascript 注释我也有同样的问题。 我用 瓦丁7.6.5 java 7
最佳答案
在 CustomLayout 中插入 Angular 代码是个坏主意。
我建议阅读文本:Vaadin and AngularJS - happy together .
有一个可用的附加组件可以让您结合 Vaadin 和 AngularJS 的优点:Vaangular
关于javascript - vaadin:使用自定义布局集成 Angular JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37272927/