gpt4 book ai didi

javascript - Thymeleaf 值发送 angularJS ng-onclick 方法

转载 作者:数据小太阳 更新时间:2023-10-29 05:45:19 25 4
gpt4 key购买 nike

我的问题是 thymeleaf 与 angularJS 的集成。我有这个 thymleaf 页面:

<div ng-controller="ctrlsubcomment" >
<div class="media" th:fragment="comments" th:each="newsComment : ${comments}">
<img class="media-object" src="/resources/images/adam1.jpg" alt="" width="52" height="52" />
<div class="media-body">
<div class="media-heading">
<span th:text="${newsComment.comment.user.name}"></span>
<span th:text="${newsComment.comment.user.surname}"></span>
<small>
<span class="glyphicon glyphicon-calendar"></span>
<span th:text="${newsComment.comment.creationTime}"></span>
</small>
</div>
<span th:text="${newsComment.comment.text}"></span>
<img th:if="${newsComment.comment.image != null and newsComment.comment.image.fileExist()}" th:src="${newsComment.comment.image.getImageData()}" alt="" width="160" height="120"/>
</div>
<div class="media-icons" >
<div class="btn-group" role="group" aria-label="...">
<span th:inline="text" th:text="${newsComment.comment.id}">${newsComment.comment.id}</span>
<a href="#" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-thumbs-up"></span> (45)</a>
<a href="#" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-thumbs-down"></span> (12)</a>
<button type="button" ng-click="addSubComment(${newsComment.comment.id})" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#cevapla">
<span class="glyphicon glyphicon-share-alt"></span>
Cevapla
</button>
</div>
</div>
<div class="cevap">
<img class="media-object" src="/images/adam7.jpg" alt="" width="52" height="52" />
<div class="media-body">
<div class="media-heading">Kemal Yapıcı<small> <span class="glyphicon glyphicon-calendar"></span> 04.11.2014 16:30</small></div>
some text.
</div>
</div>
</div>
</div>
</div>

我的 AngularJS 方法是这样的:

app.controller('ctrlsubcomment', function($scope, $http) {
$scope.newssubcomment = {
mainComment: { id : ""} ,
comment: {text: ""}
};

$scope.addSubComment = function(commentId) {
$scope.newssubcomment.mainComment.id = commentId;
alert("helllo comment : "+commentId +" " + $scope.newssubcomment.mainComment.id);
};
}

我的代码不工作。我有 AngularJS 语法错误:

"Error: Syntax Error: Token '{' is unexpected, expecting []] at column 17 of the expression [addSubComment([${newsComment.comment.id}])] starting at [{newsComment.comment.id}])].

最佳答案

我浏览了所有互联网,然后找到了解决方案。

th:attr="ng-click='addSubComment(\''+${newsComment.comment.id}+'\');'" 

引用: http://www.mattheye.com/passing-data-between-spring-mvc-and-angularjs/

关于javascript - Thymeleaf 值发送 angularJS ng-onclick 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29199089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com