Error occurred in AngularJS when trying to pass a parameter from an HTML page in order to retrieve data using

I am encountering an issue when attempting to pass a parameter from the HTML page to delete a row from the database. The http.get() method retrieves data for all books, and I am passing the ID for a specific book for deletion. However, I am facing a syntax error upon return.

Below is the HTML page featuring a delete button with a function call triggered by ng-click:

    <div class="container">

      <table class="table">
        <thead>
          <tr>
            <th>Id</th>
            <th>Name of Book</th>
            <th>Author</th>
            <th>Description</th>
            <th>No of books available</th>
          </tr>
        </thead>

        <tbody>

          <tr ng-repeat = "book in libraryBooks | filter:keyword">
            <td>{{book.id}}</td>
            <td>{{book.name}}</td>
            <td>{{book.author}}</td>
            <td>{{book.description}}</td>
            <td>{{book.count}}</td>

<td><button ng-click = "removeItem({{book.id}})">remove</button></td>
      </tr>

        </tbody>
      </table>
    </div>

The browser console is displaying a syntax error. I am passing this parameter to fetch in the controller to execute a Hibernate function for deleting the book with that specific ID.

Answer №1

simply provide the book.id

This is the way to do it:

<button ng-click = "removeItem(book.id)">remove</button>

Answer №2

It is important to note that the {{}} interpolation directive cannot be used within the ng-click directive. This is because scope variables can be directly accessed within the ng-click directive itself.

ng-click="removeItem(book.id)"

Answer №3

ng-click is a specific directive in Angular that takes in an argument from the scope. Therefore, you can implement the following code:

ng-click="deleteProduct(product.id)"

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

Incorporating Distinct Items into an Array with JavaScript

There is a Filter object that stores information about different Car Types. The data is fetched via AJAX calls - on the first call, objects 0-10 are created and added to an array. Subsequent calls bring more car types which are also appended to the array. ...

Quickest method for arranging a multi-dimensional array with dates in sequential order

I have a list of appointments with dates and times as shown below: [ ["John Doe", "10 Sep. 2017 2:00 PM"], ["Jane Smith", "10 Sep. 2017 2:00 PM"], ["Alice Johnson", "10 Sep. 2017 1:00 PM"], ["Bob Williams", "10 Sep. 2017 8:00 AM"], ["M ...

typescript api overlooking the async await functionality

My controller contains an asynchronous method that is supposed to set a results object. However, I'm facing an issue where instead of waiting for the 'await' to finish executing, the code jumps to the response object call prematurely, leavin ...

What is the best way to sort through this complex array of nested objects in Typescript/Angular?

tableData consists of an array containing PDO objects. Each PDO object may have zero or more advocacy (pdo_advocacies), and each advocacy can contain zero or more programs (pdo_programs). For example: // Array of PDO object [ { id: 1, ...

Error in Dimplejs: Line is not visible when series is empty

I have a dimplejs.org line chart set up. I am trying to colorize the Clicks data points from blue to red (blue for fewer clicks and a gradient from blue to red for more clicks). When I set the series as shown below, it works fine but the tooltip only incl ...

The parsererror occurred while executing the jQuery.ajax() function

When attempting to retrieve JSON data from using the following code: (Using jQuery 1.6.2) $.ajax({ type: "GET", url: url, dataType: "jsonp", success: function (result) { alert("SUCCESS!!!"); }, error: function (xhr, ajaxO ...

Do you find this unattractive? What are some ways to improve this unsightly JavaScript statement?

This code seems messy, how can I better structure this switch statement? function renderDataTypeIcon(dataType: string) { let iconName; switch (dataType) { case "STRING": //TODO - ENUM iconName = "text"; break; ...

What is the best way to transfer the $http response value to another function?

I currently have these two functions set up. One function, $scope.submit, handles posting data to the server and capturing the response value. The other function, $scope.addTeams, is responsible for adding teams based on the response from $scope.submit. ...

Comparing jQuery and Yahoo UI API Design

I find myself puzzled by the contrasting design approaches of jQuery and Yahoo UI APIs. I must confess, I have a strong aversion to the jQuery API, but my knowledge in web programming and JavaScript is limited, so I could be completely mistaken and end up ...

AngularJS: unique custom directive for bi-directional binding

I am facing a challenge where I need to create a directive with specific behavior: Controller: vm.mymodel = 'Hello World' Html: <custom-input mydirective="{propbind: 'data-value', propmodel: vm.mymodel}"></custom-input> ...

Having trouble accessing the latest props within a setInterval in a React functional component

I'm facing an issue where I can't seem to access the updated prop within setInterval inside Component1; instead, it keeps showing me the old value. Here's the code snippet I'm working with: import { useState, useEffect } from "reac ...

Transform a dynamic web page into a static one using Next.js

Utilizing Next.js and React.js, I create dynamic web pages. Specifically, I generate user-related web pages that need to be updated when there are changes in the user data. How can I generate static HTML pages from this updated data within Next.js? Are the ...

Issue arises after injecting HTML element into the DOM due to memory constraints and display inconsistencies

Upon executing the following script in Firefox... var d = $("<div class='test'></div>"); d.hide(); $("body").prepend(d); d.show(); ...and examining the HTML, the inserted element will have the style attribute: style="display: blo ...

Show the layout of the table in a visual format

I am struggling to showcase a table created using <ul> tags. I want the content to be displayed one after the other. Here is my code: CSS .activity-list-header > li { display: inline-block; text-align: left; width: 15.666%; list- ...

Tips for avoiding problems with quoting and using apostrophes in a JavaScript function inside a tag in a JSP file

Within my JSP, I have a string value stored in ${state.status.code} that I need to pass to a JavaScript function when a table element is clicked using onClick to trigger the showStatus function. Here is how I have attempted to achieve this: <c:set var= ...

Tips for preserving scroll location on Angular components (not the window) when navigating

My current layout setup is like this: https://i.sstatic.net/hOTbe.png In essence <navbar/> <router-outlet/> The issue I'm facing is that the router-outlet has overflow: scroll, making it scrollable (just the outlet section, not the ent ...

Configuration of injected services in IONIC 2

I am curious about how the services from injected work in IONIC 2. Specifically, my question is regarding the number of instances that exist when one service is used in two or more controllers. Previously, I asked a colleague who mentioned that IONIC 2 op ...

Navigating in AngularJS with various URL parameters

Within my application, I am in need of using routes that require multiple attributes from the URL to be passed into PHP. The current setup that is functioning correctly is as follows: .when('/jobs/:type', { templateUrl: function(attrs){ ...

AngularJS - Monitoring the Completion of Rendered Trees in Recursive ng-includes

My current project involves rendering a hierarchical tree recursively using ng-include. If you're interested, you can take a look at this fiddle. The issue I'm facing is that the link function within my code gets called before the rendering proc ...

"Transmitting a message with socket.io upon establishing connection

Currently getting the hang of socket.io and giving it a try. I have a straightforward app where clicking the display button shows an image on the screen in real time. I have a couple of questions. Firstly, my main concern is regarding the synchronization ...