我的问题类似于
this existing question
i、 一个Web项目已经在使用-Spring MVC+Angular1。x+JSP+JavaScript等。
所以我建立了一个单独的Angular2项目,构建了它,并在tiles的布局JSP中包含了最终的JS文件。
在我的新主体jsp中,当我使用angular2根组件时,我的jsp显示得非常完美,但应用程序的所有其他页面都显示了以下错误,
core.es5.js:1020 ERROR Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.selectRootElement (platform-browser.es5.js:2791)
at createElement (core.es5.js:9172)
at createViewNodes (core.es5.js:12146)
at createRootView (core.es5.js:12075)
at Object.createProdRootView [as createRootView] (core.es5.js:12760)
at ComponentFactory_.create (core.es5.js:9858)
at ComponentFactoryBoundToModule.create (core.es5.js:3333)
at ApplicationRef_.bootstrap (core.es5.js:4763)
at core.es5.js:4546
at Array.forEach (<anonymous>)
defaultErrorLogger @ core.es5.js:1020
zone.js:654 Unhandled Promise rejection: The selector "app-root" did not match any elements ; Zone: <root> ; Task: Promise.then ; Value: Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.selectRootElement (platform-browser.es5.js:2791)
at createElement (core.es5.js:9172)
at createViewNodes (core.es5.js:12146)
at createRootView (core.es5.js:12075)
at Object.createProdRootView [as createRootView] (core.es5.js:12760)
at ComponentFactory_.create (core.es5.js:9858)
at ComponentFactoryBoundToModule.create (core.es5.js:3333)
at ApplicationRef_.bootstrap (core.es5.js:4763)
at core.es5.js:4546
at Array.forEach (<anonymous>) Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.selectRootElement
上面的错误在控制台上,其他JSP页面保持正常工作,而这个后台错误对它们没有任何影响。
我已经包括了angualr2 JS文件外面的身体标签在底部。
我们将建立一个自动过程,将文件从Angualr2 UI项目构建和复制到Spring MVC项目,只有那些最终的JS文件将与应用程序一起部署。
它是一个首次加载页面的Spring MVC控制器——一个JSP。