What could be causing ng-repeat to malfunction?

My ng-repeat is not working with the table - only the header part is being displayed in the output. I have checked my binding and it seems to be correct, but I know I am missing something. Can someone please help me figure out what I am doing wrong?

JAVA SCRIPT:

var myapp=angular.module("MyApp",[]);
var controller=function($scope)
{ 
        var technology1=[
            {Name: "C#",Likes: 0,Dislikes: 0},
            {Name: "JAVA",Likes:0,Dislikes:0},
            {Name: "Python",Likes:0,Dislikes:0}
        ];
        $scope.technology=technology1;
        $scope.incrementLikes=finction(technology)
        {
            technology.Likes++;
        }
        $scope.discrementLikes=function(technology)
        {
        technology.Dislikes++;
        }
}
myapp.controller('MyController',controller);
    <html ng-app="MyApp">
    <head>
        <title></title>
        <script src="angular.js"></script>
        <script src="Day2.js"></script>

    </head>
    <Body ng-controller="MyController">
    <div >
        <table border='2'>
        <thead> 
            <tr>
            <th>Name Of Technology</th>
            <th>Likes</th>
            <th>Dislikes</th>
            <th>Likes/Dislikes</th>
            </tr>
        </thead>

        <tbody>
        <tr ng-repeat="tech in technology">
            <td>{{tech.Name}}</td>
            <td>{{tech.Likes}}</td>
            <td>{{tech.Dislikes}}</td>
            <td>
            <input type="button" value="Like" ng-click="incrementLikes(tech)">
            <input type="button" value="Dislikes" ng-click="decrementLikes(tech)">
            </td>
        </tr>
        </tbody>
        </table>
    </div>
    </Body>
    </html>

Answer №1

Revise this sentence

        $scope.incrementLikes=function(technology)

with

        $scope.incrementLikes=function(technology)

Answer №2

There is a minor error in your myController controller code. Please replace finction with function.

Answer №3

Pankaj Parkar made a valid point about correcting the "finction" typo and referencing $scope.technology.Likes and $scope.technology.dislikes when incrementing their values.

Make these updates:

$scope.incrementLikes=function(technology)
    {
        $scope.technology.Likes++;
    }
$scope.discrementLikes=function(technology)
    {
    $scope.technology.Dislikes++;
    }

In summary, remember to use $scope before technology.Likes and technology.Dislikes in your functions.

Answer №4

After reviewing the code, it appears to be fully corrected. I would like to point out that you should not add "$scope.technology.Likes++;" or "$scope.technology.Likes++;" in your increment/decrement functions. The existing code is sufficient as it updates the likes/dislikes property on the "tech" object passed in from the click function.

var myapp=angular.module("MyApp",[]);
var controller=function($scope)
{ 
        var technology1=[
            {Name: "C#",Likes: 0,Dislikes: 0},
            {Name: "JAVA",Likes:0,Dislikes:0},
            {Name: "Python",Likes:0,Dislikes:0}
        ];
        $scope.technology=technology1;
        $scope.incrementLikes=function(technology)
        {
            technology.Likes++;
        }
        $scope.decrementLikes=function(technology)
        {
        technology.Dislikes++;
        }
}
myapp.controller('MyController',controller);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html ng-app="MyApp">
    <head>
        <title></title>
        <script src="angular.js"></script>
        <script src="Day2.js"></script>

    </head>
    <Body ng-controller="MyController">
    <div >
        <table border='2'>
        <thead> 
            <tr>
            <th>Name Of Technology</th>
            <th>Likes</th>
            <th>Dislikes</th>
            <th>Likes/Dislikes</th>
            </tr>
        </thead>

        <tbody>
        <tr ng-repeat="tech in technology">
            <td>{{tech.Name}}</td>
            <td>{{tech.Likes}}</td>
            <td>{{tech.Dislikes}}</td>
            <td>
            <input type="button" value="Like" ng-click="incrementLikes(tech)">
            <input type="button" value="Dislikes" ng-click="decrementLikes(tech)">
            </td>
        </tr>
        </tbody>
        </table>
    </div>
    </Body>
    </html>

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

Guide to implementing server-side data loading in App.js using Next.js

Is there a way to fetch the layout data along with the page without adding it to every individual page? The issue I'm facing is that my layout component, loaded once on App.jsx, remains consistent throughout the session. However, due to SSRed page loa ...

Disparity in React app: Misalignment between debugger and console output

Throughout the years, I've encountered this issue in various ways, and I have finally been able to articulate it. Take a look at the code snippet below: import React, {Component} from "react"; import aFunction from "./Function"; export default class ...

Tips for adjusting a pre-filled form?

When a form is rendered by onClick from a component, it loads with values. I want to be able to edit these current values and then perform an update operation. Here is the link to the sandbox: https://codesandbox.io/s/material-demo-forked-e9fju?file=/demo ...

Rest parameter ...args is not supported by Heroku platform

When interacting with Heroku, an error message SyntaxError: Unexpected token ... appears. What modifications should be made to this function for compatibility with Heroku? authenticate(...args) { var authRequest = {}; authRequest[ ...

Creating various functions for Joomla's AJAX component development

My component is currently working smoothly with AJAX and mootools. The view.raw.php file contains only one function called display. I've been attempting to add other functions within the component that can be accessed through AJAX, but have been facin ...

Guide on making a persistent sidebar using CSS and JavaScript

I'm in the process of developing a website that features a main content area and a sidebar, similar to what you see on Stack Overflow. The challenge I am facing is figuring out how to make the sidebar remain visible as a user scrolls down the page. T ...

"Enhance Your WordPress Website with the Power of jQuery

I have been developing a unique Wordpress plugin that incorporates a grid loading effect using jQuery. The script I have implemented is as follows: <script type="text/javascript"> new GridScrollFx( document.getElementById( 'grid' ), { ...

Vue Js and form-data Event: A deeper look into handling form

Hey there #Vue.js2 I'm facing an issue while trying to create a function that is called within a form submit event. This particular function needs both the EVENT and ID as parameters. The problem arises when I call this function, as I am unable to spe ...

AngularJS Accordion Component: A Handy Tool for Organ

I have been trying to implement an Accordion in my angular project by sending HTML structure from a controller. However, despite following the documentation closely, the Accordion is not displaying as expected. Here is a snippet of the code I am using: v ...

Prolong the duration before the submenu closes on a div-based css menu

I have created a unique horizontal menu using DIVs without the use of ul and li lists. Currently, I am searching for a way to delay the collapse of the submenus when the mouse moves out. I don't mind if the solution involves JavaScript, jQuery, or CSS ...

Tips for saving the ajax response to the browser cache using jquery

I am currently working on storing the ajax response in the browser cache. I have successfully managed to store it for URLs like (example.com), but now I am facing a challenge with storing data for URLs like (example.com?xyz=abc%20efg&mno=hjk). Here is ...

Updating a user's information post-login: A step-by-step guide

I'm encountering some challenges when it comes to modifying a user's information post-login. I am utilizing the MEAN stack (MongoDB, Express, AngularJS, Node.js) alongside Passport.js. I suspect that the issue may lie within the express route, th ...

Having trouble with React Testing Library throwing an error every time I try to use fireEvent on an input text?

When attempting to utilize the "fireEvent" method from React Testing Library, I encountered an error as shown below: MainSection.test.js: test('Verifying SearchBar functionality', async () => { render(<SearchBar />); const text ...

What is the best way to access all sections of a JSON file containing nested objects within objects?

Here is an example of my JSON file structure: [{ "articles": [ { "1": { "sections": [ {"1": "Lots of stuff here."} ] } }, { "2": { "sections": [ {"1": "And some more text right here"} ] } } }] The c ...

Guide on how to dynamically add AJAX JSON array response to an HTML table

Hey! I need some advice on how to dynamically append a JSON Array response to an HTML table after submitting a form using AJAX. Here's the scenario: This is my form : <form id="myForm" method="POST"> <input type=" ...

Setting URL parameters dynamically to the action attribute of a form using JavaScript code

I'm having trouble posting Form data to my Server. I am dynamically setting the element and its URL parameters for the action attribute, but it seems like it's not recognizing those attributes. Can you help me figure out what I'm doing wrong ...

I am having an issue with my registration form in node.js where it does not redirect after submitting

I am currently working on implementing a registration form using node/express for my website. The routes are all set up and the database connection is established. However, I am encountering some issues when users try to submit the registration form on th ...

Issue: Unhandled promise rejection: BraintreeError: The 'authorization' parameter is mandatory for creating a client

I'm currently working on integrating Braintree using Angular with asp.net core. However, I've encountered an issue that I can't seem to solve. I'm following this article. The version of Angular I'm using is 14, and I have replicate ...

I'm having trouble getting FlowType.js to function properly

I have added the following code just before the closing </body> tag, but unfortunately, it seems like the type is not changing as expected. I am struggling to identify what mistake I might be making. Check out FlowType.JS on GitHub View the code on ...

Obtaining variable content from a JavaScript function

Learning JS with documentation has been a challenging journey for me. The concept of variables inside and outside a function still confuses me. I'm interested in creating a module that allows me to reuse code written in different parts of my program ...