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

The CSS files are not loading automatically in my React application using Vite

I am facing an issue with importing css and js files into a view in React using vite. The styles are not loading properly, and I have to keep commenting and uncommenting the imports in my code for them to be recognized when entering the view. Below is a s ...

When encountering a 404 redirect, CSS and JS files may fail to display

I created a unique error message using .htaccess, incorporating CSS and JS in separate folders. Although it functions properly when accessed directly, integrating these resources into the 404 Error message results in only the HTML text being displayed with ...

Ways to deactivate selecting rows in a datatable

Is there a way to deactivate the select feature specifically within datatables? An example of using ctrl+a for disabling select all function is available here https://i.stack.imgur.com/RQNXT.png ...

How can I troubleshoot a C# web method called from an AJAX request in

I have a asp.net (web forms) c# code behind page that contains a web method which I trigger through an ajax call on the same page. Upon making the ajax POST call, I encounter a generic "Internal server error has occurred" message. To troubleshoot this is ...

Improving Performance in AngularJS Through Efficient Scope Passing Between Controllers

I am facing a situation in my AngularJS project where I have two controllers - controller 1 is constantly present in the view, while controller 2's visibility can change based on the view. In order to ensure that controller 1 has access to certain sco ...

Angular is known for sending only the fields that have changed to the update method

I need help with optimizing my save method. When a user clicks SAVE, I only want to send the fields that have been changed instead of all 50+ fields on the page. This will reduce the amount of data being sent every time. Api.Admin.update({ obsoleteDat ...

What is the best way to process an API call entirely on the server without revealing it to the client?

Seeking guidance on a technical issue I've encountered. On my website, x.com, a form submission triggers an API call to y.com, yielding a JS hash in return. The problem arises when Adblocker Plus intercepts the content from y.com, causing it to be bl ...

Put a pause on a section of code

var ajaxRequestqqq; // The variable that enables Ajax functionality! try{ // Opera 8.0+, Firefox, Safari ajaxRequestqqq = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequestqqq = new ActiveXObject("Msxml2.XMLHTT ...

Bypassing the "Your connection is not private" error in NodeJS + Express with fetch() using Javascript

Presently, I have a setup with a NodeJS + ExpressJS client-side server that communicates with the back-end server via API calls. However, every time I make a call, I need to manually navigate to the URL of the API back-end server and click on Advanced -> ...

What is the best way to invoke a function in one View Model from within another View Model?

I am looking to divide my DevExtreme Scheduler into two separate view models. One will be responsible for displaying the Scheduler itself, while the other will handle the Popup and button functionality. Despite having everything set up, I am struggling to ...

What are the steps to accessing validation errors using express-validator?

Recently, I delved into the world of express-validator to enhance my skills. Despite going through the documentation thoroughly, there's a query lingering in my mind that might have already been addressed in the docs. My confusion arises from needing ...

Issue with dynamically generated modal popup not registering jQuery 'on' event handler

Originally, I believed that jQuery's on event handler had the capability to 'listen' for dynamically generated elements and that it was meant to replace the functionality of live. However, in practice, when using on, I found that it was not ...

Steps for regularly executing 'npm run build' on the server

My website doesn't require frequent content updates, as users don't always need the latest information. As a result, most pages are generated server-side and served as static pages. There will be occasional database updates that need to be visib ...

TypeScript async function that returns a Promise using jQuery

Currently, I am facing a challenge in building an MVC controller in TypeScript as I am struggling to make my async method return a deferred promise. Here is the signature of my function: static async GetMatches(input: string, loc?: LatLng):JQueryPromise& ...

Tips for executing an SQL query containing a period in its name using JavaScript and Node.JS for an Alexa application

Hello there, I've been attempting to make Alexa announce the outcomes of an SQOL query, but I'm encountering a persistent error whenever I try to incorporate owner.name in the output. this.t("CASEINFO",resp.records[0]._fields.casenumber, resp.r ...

I require assistance in displaying a dynamic, multi-level nested object in HTML using AngularJS

I have a complex dynamic object and I need to extract all keys in a nested ul li format using AngularJS. The object looks like this: [{"key":"campaign_1","values":[{"key":"Furniture","values":[{"key":"Gene Hale","values":[{}],"rowLevel":2},{"key":"Ruben A ...

Froala Editor: retrieve content and send it via an AJAX request

I am having an issue with content placement and saving on the server. So, I have been using: `$(".selector").editable("getHTML");` This is supposed to retrieve the content in HTML format according to the documentation. For example, this is a sample of th ...

Tips for locking the position of a table header and allowing only the table body to scroll

I have designed a table with tbody consisting of 2 tr elements. One tr is used for hiding/showing data. I am trying to keep the Table header fixed while only scrolling the table body. However, as I am using angular js ng-repeat on the tbody, I am encounte ...

State loss occurs when moving to a different page using next/link

Currently, I am working on a library application with Next.js. Within this project, there are two main pages: BooksPage, which displays a list of all books, and BookPage, where detailed information about a specific book is shown. The components involved in ...

What are the best strategies for creating HTML website designs that are both scalable, adaptable, and versatile?

As a beginner in HTML website design, I have recently started using HTML, CSS, jQuery, and JavaScript for designing websites. After creating a site with almost forty webpages, the client requirements are changing, requiring changes to be made across all ...