Transfer a table row between tables - AngularJS

I am seeking guidance on how to implement ng-repeat in order to transfer data from one table to another. Essentially, I have a "master" table that displays data fetched from an API request. Each row in this table has a button labeled "favorite-this-row". When a user clicks this button, I want the respective row to be moved to a table named "favorite-table" where the data will be displayed.

Here is a snippet of my "Master" table:

<md-card flex="45" flex-sm="100" flex-md="100" flex-xs="100" 
    ng-show="(account|filter:searchName).length > 0"
    ng-repeat="account in containers | groupBy: 'accountId'  | toArray | filter:searchName track by $index ">

        ... HTML code omitted for brevity...

    **//Favorite button**

<md-button ng-init="item.isfavorite = false;"
       ng-class="{yellow : item.isfavorite}"
       ng-click="item.isfavorite =!item.isfavorite; AddFavorite(item.isfavorite,container.containerId)"
       class="md-icon-button md-accent md-warn" aria-label="Favorite">      
<ng-md-icon icon="favorite" ng-init="item.isfavorite = false;"></ng-md-icon>
</md-button>

<p ng-if="item.isfavorite">Remove from favorites - {{item.isfavorite}} </p>
<p ng-if="!item.isfavorite">Add to favorite</p>

And this is my "Favorite" table:

<table>
   <tr ng-repeat="x in containers" ng-show="item.isfavorite">
         <td>s{{ x.containerId }}</td>
         <td>s{{ x.accountId }}</td>
    </tr>
</table>

Upon clicking the

<md-button ng-init="item.isfavorite = false;" ....>
, I aim to move the row to the "Favorite" table displaying containerId and accountId. Although I have used ng-show="item.isfavorite", the functionality does not seem to work as expected.

The function

AddFavorite(item.isfavorite,container.containerId)"
is temporarily a placeholder console.log in the controller.

I would appreciate any assistance or insights on this matter. Thank you!

Answer №1

According to @avius, the correct code should use account instead of item. Additionally, in the favorite table, x should be used instead of item. It should look something like this:

<md-button class="md-raised" ng-click="account.isfavorite =!account.isfavorite">Button</md-button>

<p ng-if="account.isfavorite">Remove from favorites - {{account.isfavorite}} </p>
<p ng-if="!account.isfavorite">Add to favorite</p>



 <tr ng-repeat="x in containers" ng-show="x.isfavorite">

Feel free to check out this plunker

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 navigation bar fails to respond when clicked on mobile devices

Calling all developers! I need a helping hand to tackle an issue that's holding me back from completing this website. Can someone please take a look at on their smartphone browser and figure out why the responsive menu icon isn't working when cl ...

Alterations to the current state yield no effect

I've encountered an issue while attempting to navigate back to a sibling state within my Ionic app. Despite successfully doing this in the past, I'm facing difficulties this time around. Below is where I'm using the $state: dataProvider.cu ...

Challenges Encountered When Inputting Year in ReactJS Date Picker Component

I've encountered a problem with a date input component in my ReactJS project and need some assistance with resolving two issues: Problem 1: Year Input Length The first issue is that the year input field allows six digits, but I want to restrict it to ...

Utilizing the $(this).text method in combination with the content class

In order for the text of the click function to be the final variable, I attempted using $(this).text, but unfortunately it did not produce the desired outcome. Placing the class at the end resulted in both p lines appearing. My goal is to only display the ...

How to retrieve nested menu items within the scope by utilizing JSON and AngularJS

I have recently started working with angular and am facing difficulty in accessing the submenu items within my angular application. While I can successfully access the top level menu items, I am struggling to retrieve the second level items. Here is a sni ...

Ways to retrieve information beyond the scope of the 'then' method

One issue I am facing involves a piece of code that is only accessible inside of the 'then' function. I need to access it outside of this block in order to utilize it in other parts of my program. $scope.model = {'first_name':'&ap ...

The implicit wait feature in WebDriver JavaScript seems to be ineffective

Waiting for the error message to appear seems to be a bit tricky. I tried using browser.driver.manage().timeouts().implicitlyWait() but had to resort to using browser.driver.sleep() instead. this.getErrorMessage = function () { var defer = protracto ...

When implementing tooltips in Apexchart's JavaScript, the y-axis second does not appear in the chart

Typically, when I append data to the second y-axis as an array, it works perfectly. However, for some reason, when I try to append a collection to the data, it no longer shows with two y-axes simultaneously. I even tried adding x and y as the Apex documen ...

Guide to assigning an integer value to a string in Angular

Is there a way to change integer values in a table to actual names and display them on a webpage by setting a scope in the controller and passing that string to the HTML? For example, this is an example of the HTML code for the table row: <thead> ...

Passport appears to be experiencing amnesia when it comes to remembering the user

After extensive research online, I have yet to find a solution to my issue. Therefore, I am reaching out here for assistance. I am currently working on implementing sessions with Passport. The registration and login functionalities are functioning properl ...

Exploring the selected object in VueJs

I am attempting to showcase a fullName function using the selected value HTML : <div id="test"> <h1>{{ sayHello }}</h1> <select v-model="selected"> <option v-for="person in persons" v-bind:value="person.about"> {{ per ...

Textbox textchange event triggers Javascript function when Checked=True

$('.LblQTY').on('input', function () { var currentRow = $(this).closest('tr'); var rate = parseFloat(currentRow.find('.LblRate').text()); var quantity = parseFloat($(this).val() == '' ? '0& ...

Callbacks in Laika tests go untriggered

Meteor.collection.insert() allows for the use of a callback as one of its arguments. To demonstrate, you can start a new Meteor project and execute the following code in the browser's console. my_collection = new Meteor.Collection("myCollection"); my ...

Unable to scroll to the top of the page with JavaScript

I tried the code below but it didn't quite do the trick. Can someone assist me with refreshing the page to the top every time it loads? window.addEventListener('load', function(){ window.scrollTo(0,0) }) window.onload = (event) => { ...

Displaying the format when entering a value with react-number-format

How to Display Format Only After Full Value Inserted in react-number-format I recently implemented the react-number-format package for formatting phone numbers. import { PatternFormat } from 'react-number-format'; <PatternFormat value={v ...

``After initialization, the service is unable to retrieve the object as

I have a special service that stores specific objects to be shared among different controllers. Here is an example of the code I am using: $rootScope.$on('controller.event', function(event, arg){ self.backendConnectorService.getBac ...

Learn the process of appending an item to a list using Vue.js

Recently starting with vue.js and facing an issue: data: { ws: null, newMsg: '', username: null, usersList: '' }, created: function() { var self = this; this.ws = new We ...

Encountering a POST 504 error while attempting to proxy an Angular application to a Node server

error message: Failed to connect to http://localhost:4200/api/user/login with a 504 Gateway Timeout error. Encountered this issue while attempting to set up a login feature in my Angular application and establish communication with the Express backend. Th ...

Modify the input once all the angular data has been collected

In my controller, I have a function that retrieves data from the database (id, name, surname, email, review): function loadAll() { UniversalService.GetAll() .then(function (a) { $scope.all=a; }); } Next ...

Creating a unique Voronoi Diagram wrap

I am currently working on the creation of a fantasy-style map that is procedurally generated using the cells of a Voronoi diagram to determine different terrains. While working on the tectonic plate generation, I came to the realization that having wrappi ...