我試圖通過使用自定義佈局像這樣在vaadin角JS應用程序集成整合的角度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);
}
我導入JS腳本使用importJs方法。 我第一次訪問頁面時,js文件被加載並且工作。 第二次,它不起作用。 就好像腳本沒有被導入。 我沒有看到我的代碼有什麼問題? 使用Javascript註釋我有同樣的問題。 我使用 vaadin 7.6.5 java 7
謝謝德拉甘的回答: 爲了我們每一個顯示我使用的頁面時excecute這個腳本。 我已閱讀關於Vaangular。 我試過了。但是這取決於java 8. 我使用的是java 7. – benji
無論如何CustomLayout不會幫助你。您可以嘗試將Angular組件集成爲其他任何Java腳本組件,如https://vaadin.com/docs/-/part/framework/gwt/gwt-javascript.html中所述。另外,我不完全確定Vaangular是java 8只兼容。你確定嗎? –