可以同时使用angular2和Thymeleaf吗? [英] can I use angular2 and Thymeleaf together?

查看:188
本文介绍了可以同时使用angular2和Thymeleaf吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Thymeleaf th:放在angular2模板中,但是th:不会编译.我有什么办法可以将它们一起使用吗?

I put the Thymeleaf th: in angular2 templates, but the th: wont compile. Is there any way I can use them together?

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在服务器端处理.

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.

您有两个选择:

  • 一起使用Angular和(例如)Spring,您将在其中使用REST API,将数据从后端公开到Angular(前端),然后 您将使用*ngFor指令.

  • 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.

将Thymeleaf与诸如Spring MVC或Spring Webflow之类的框架一起使用 等等.(也可以在这里使用Angular,但您必须知道 Thymeleaf是在服务器端处理的,因此 Thymeleaf代码转换为JavaScript文件,并期望它能 已处理).

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).

这篇关于可以同时使用angular2和Thymeleaf吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆