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

Yut*_*Guo 3 spring-mvc angularjs thymeleaf angular2-template angular

我把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 {}
Run Code Online (Sandbox Code Playgroud)

小智 11

你将两个框架混合在一起.Angular是在客户端处理的前端框架,另一方面Thymeleaf是在服务器端处理的.

您有两种选择:

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

  • 使用Thymeleaf和Spring MVC或Spring Webflow等框架(也可以在这里使用Angular,但你必须知道Thymeleaf是处理服务器端的,因此你不能将Thymeleaf代码放到JavaScript文件中并期望它被处理).