【问题标题】:How to combine AngularJS and Thymeleaf templates如何结合 AngularJS 和 Thymeleaf 模板
【发布时间】:2017-03-28 20:57:54
【问题描述】:

我正在将当前使用 Thymeleaf 的网页转换为使用 AngularJS。

我想转换包含 Thymeleaf 的后续块

<form th:action="@{?deleteLog}" th:object="${log}" method="post" class="in-line">
    <input type="hidden" th:value="${log.vid_id}" name="vid_id" />
    <input type="hidden" th:value="${log.id}" name="id" />
    <button type="submit" class="btn btn-danger">Delete</button>
</form>

这些th:value 变量被传递给我的控制器类中的@PostMapping 方法,然后使用这些变量从我的数据库中删除一个条目。

如何使用 AngularJS 实现这一点?采取与我相同的方法

<form th:action="@{?deleteLog}" method="post" class="in-line">
    <input type="hidden" th:value="{{x.vid_id}}" name="vid_id" />
    <input type="hidden" th:value="{{x.id}}" name="id" />
    <input type="button" value="Remove" class="btn btn-danger" ng-click="removeRow(tableList.id)" />
</form>

removeRow() 函数成功地从 UI 中的表中删除了行,我只需要将 {{x.vid_id}}{{x.id}} 值发送到我的控制器类中的方法。

我显然没有使用正确的语法,因为我在尝试使用 Angular 时遇到了 th:value="{{x.id}}" thymeleaf 变量的解析错误。我也试过th:value="${{x.id}}"'th:value="${{{x.id}}}"

我无法在网上找到有关传递 Angular 变量的任何信息。这甚至可能吗?

【问题讨论】:

    标签: java angularjs variables spring-boot thymeleaf


    【解决方案1】:

    您不应将 AngularJS(用于客户端 HTML 模板的 SPA 框架)与 Thymeleaf(用于服务器端 HTML 模板的库)混合使用。您应该选择在服务器或客户端上进行模板化并坚持下去。

    将这两者结合起来根本没有意义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2010-12-14
      • 2019-10-31
      相关资源
      最近更新 更多