can I use angular2 and Thymeleaf together?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 13:46:27

You're mixing two frameworks for frontend together. Angular is frontend framework processed at client side, on the other hand Thymeleaf is processed server side.

You have two options:

  • Use Angular and (for example) Spring together, where you'll use REST API to expose data from backend to Angular (frontend), and then you'll use *ngFor directive.

  • Use Thymeleaf with frameworks such as Spring MVC or Spring Webflow etc. (It's also possible to use Angular here but you have to know that Thymeleaf is processed server side, so you can't put Thymeleaf code to JavaScript file and expect that it gets processed).

Yes, you can use Angular and Thymeleaf together. In your code, you have put the layout info into the javascript, which is not a good practice; you should pull it out from javascript code and make it a html template. You would need to pay attention to where to put the html template. Please check my post at here:

Make Spring Thymeleaf work with AngularJS routeProvider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!