AngularJS ng-onclick method sending value to Thymeleaf

I am facing an issue with the integration of Thymeleaf and AngularJS. Below is the Thymleaf page I have:

<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>
                            Reply
                        </button>
                </div>
            </div>
            <div class="reply">
                <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>

Here is my AngularJS method:

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

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

However, I am encountering a syntax error in my code:

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

Answer №1

After extensive searching on the internet, I finally discovered a solution.

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

For more information, please visit:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customizing the appearance of charts in AngularJS using the Chart.js

I just started experimenting with AngularJS and recently created a horizontal bar chart using Chart.js and HTML. My next step is to make the chart dynamically appear on the page with the help of AngularJS. Can someone please provide some guidance on how I ...

Angular's Readonly component fails to display line breaks

I am currently developing an Angular application using C#. One issue I have encountered is with read-only components that display saved data from the database. For instance, when inputting text into a Textarea component, such as: hello there hello ...

When assigning JSON to a class object, the local functions within the class became damaged

This is a demonstration of Object Oriented Programming in JavaScript where we have a parent Class called Book with a child class named PriceDetails. export class Book { name: String; author: String; series: String; priceDetails: Array<Price> ...

Create PDF files on-the-fly using the html-pdf module

Recently, I've been using the npm package html-pdf for generating PDF invoices dynamically. However, I encountered a problem where instead of saving values to the PDF file, it was saving ejs code. Does anyone have any insight on why this might be happ ...

Adjusting webpage background with JavaScript

I've been struggling with this for the past six hours and can't seem to get it right. I've checked out various solutions on Stack Overflow, but nothing seems to work. What am I missing here?!? My html5 page doesn't have a background an ...

Revamping JSON structure by identifying id references

I recently attempted to update the city name within the JSON object provided below. "City":[ { "Name":"Delhi", "id":"c5d58bef-f1c2-4b7c-a6d7-f64df12321bd", "Towns":[ ...

Load images in advance using this script

Using a script to load images on two websites, the image is placed inside a div with the ID div-to-load-external-image Encountering an issue where PageSpeed Insights advises to preload these images, seeking guidance... Any assistance will be appreciated. ...

Guide on incorporating a refresh button to automatically update information from a database in MaterialUI's Datagrid

Recently diving into JavaScript, I encountered a common issue: The data for my table is sourced from a MySQL database through Axios Whenever CRUD operations are performed in the web app, the database is updated accordingly Although backend changes ...

What could be causing React to throw an error?

Check out this React Component: GeneralInformation = React.createClass({ totalCaptialRaisedPanel: function() { var offeringInfo = this.props.company.data.offerings.data[0]; var percentageComplete = (offeringInfo.capital_raised / offer ...

What is the method for defining an Angular directive within the link function of another directive?

I am in the process of developing a unique server-validate directive that verifies form input asynchronously by sending a partial form to our server backend for validation and analyzing the response. I envision using it in this manner: <input type="tex ...

Retrieve file server domain using JavaScript or jQuery

I'm trying to extract the domain name without the "http(s)://www." from a file link. For example, if the script returns "example.com", I want it to parse through links like "http://www.example.com/file.exe" or "https://example.com/folder/file.txt#some ...

Using PrimeFaces selectors to update a non-JSF component with Ajax

Can Primefaces selectors - PFS be used to update any html fragment? Take a look at this scenario: <h:outputText id="test" value="#{testBean.date}"/> <span id="test2"><h:outputText value="#{testBean.date}"/></span> <p:commandBut ...

How can I arrange the ng-class based on the clicked item's order?

http://plnkr.co/edit/pUtuZy?p=preview In this scenario, there are three different border classes available: .border1 { border: 1px solid #66FFFF; } .border2 { border: 1px solid #33CCFF; } .border3 { border: 1px solid #0099FF; } The goal is to as ...

Utilizing React to adapt to varying HTML layouts while maintaining consistent component usage

How can I create an App with two different views for mobile and desktop without relying solely on CSS Media Queries? I have been searching for guidance but so far haven't found a solution. Any advice or direction on where to find documentation or oth ...

The Ajax request functions correctly in Chrome and Safari but encounters issues in Firefox and Internet Explorer

I've encountered an issue with jQuery where the call is failing when making a request with base64 authorization header in the beforeSend function. It's a simple request to retrieve projects. function GetProjects(full){ var query = "/Projects"; $ ...

Do GPU-intensive animations get impacted by the CPU's load?

I have set up a special compositing layer for a div with the following unique styles: div { position: absolute; height: 50px; width: 50px; background: #900; top: 100px; left: 200px; will-change: transform; transform: translateZ(0); } Afte ...

Passing numerous PHP echo values to multiple text fields through jQuery AJAX

Check out my PHP file where I will be returning two echoes using jQuery Ajax <?php $data=$_POST['data1']; $data2="h"; if($data2==$data) { echo "john"; echo "usa"; } else { echo "Error"; } ?> This is how I call it with Ajax and populate ...

Updating and submitting data with Ajax using the `h:commandButton` component

Is there a way to update a div and achieve partial submission with the <h:commandButton> element? In the past, I utilized the <p:commandButton> for partial submission by setting the ajax attribute to true and updating the :statusBlock. Howeve ...

An issue with Nuxt.js causing body parameters to not be passed successfully while using this.$http.post

I've encountered an issue where using the @nuxt/http this.$http.post and this.$http.patch methods is causing problems with parsing body parameters during posting. Strangely, it used to work perfectly fine before, leaving me unsure of where to even beg ...

Twilio SMS Notification: The Class extension value provided is not a valid constructor or null

When attempting to utilize Twilio for sending SMS messages in a Vue.js project, I encountered an error while accessing Tools -> Developer Tools. <template> <div> <input type="text" v-model="to" placeholder="Phone ...