angularjs - 我可以一起使用 angular2 和 Thymeleaf 吗?

标签 angularjs spring-mvc angular thymeleaf angular2-template

我将 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/

相关文章:

javascript - 显示来自前端的 AngularJS 输入

java - 如何在json格式的restTemplate中将MediaType设置为UTF-8

java - 错误: cvc-elt. 1:找不到元素 'beans'的声明

java - SpringBoot 和 GitLab CI 运行测试

Angular 5 国际化 html 方向属性?

angular - ionic 2 : custom provider causing "Can' t resolve all parameters"

javascript - 从 ionic Controller 访问 Cordova 插件

javascript - AngularJS - 如何在绑定(bind)的 html (ngBindHtml) 上设置事件

angular - Angular2 示例中的图像路径混淆

javascript - Angular ui 路由器 : warn user when leaving a specific page