我将 Thymeleaf th: 放在 angular2 模板中,但 th: 无法编译。有什么办法可以一起使用它们吗?
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<table xmlns:th="http://www.w3.org/1999/xhtml">
<tbody>
<tr>
<th>User Name</th>
<th th:each="role : ${roles}">
<div class="row">
<div th:text="${role.type}"></div>
</div>
</th>
</tr>
</tbody>
</table>`,
})
export class App {}
最佳答案
您正在将两个前端框架混合在一起。 Angular 是在客户端处理的前端框架,而 Thymeleaf 是在服务器端处理的。
你有两个选择:
同时使用 Angular 和(例如)Spring,您将在其中使用 REST API 将数据从后端公开到 Angular(前端),然后 您将使用
*ngFor
指令。将 Thymeleaf 与 Spring MVC 或 Spring Webflow 等框架结合使用 等等(这里也可以使用 Angular 但你必须知道 Thymeleaf 是在服务器端处理的,所以你不能放 Thymeleaf 代码到 JavaScript 文件并期望它得到 已处理)。
关于angularjs - 我可以一起使用 angular2 和 Thymeleaf 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40343157/