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

Errors encountered while running `npm install discord.js`

I am currently facing an issue while trying to install discord.js. Unfortunately, I keep encountering the following errors: npm ERR! cb() never called! npm ERR! This is an error with npm itself. Please report this error at: npm ERR! <https://npm.co ...

Uncovering the power of injected JavaScript objects within Protractor

Our application loads requirejs, which then loads angularjs and other javascript modules. I am curious if there is a way to access these LOADED modules (angularjs, javascript modules) in a Protractor test. It's important that we are able to retrieve t ...

The functionality of a progressive web application while offline is experiencing issues when using Angular Js 1.5.x

In my pursuit to develop a progressive web app using Angular 1.5 with the assistance of Gulp, I have implemented a service worker (sw.js) using the sw-precache module in npm. Below is an excerpt from my index.html: <!doctype html> <!-- ...

How can I retrieve the ultimate value of a JQuery UI Slider and store it in a PHP variable?

I am looking to add 2 JQ UI Sliders to a single page on my PHP website. I need to capture the final values from both sliders (the last value when the user stops sliding) and store them in PHP variables for multiplication. How can I accomplish this task? I ...

What is the best way to create an array from every individual line in a textarea using AngularJS?

I am trying to create a textarea that is linked to a JS array, where each line in the text area corresponds to an entry in the array. I have been experimenting with ngList and its optional parameter for specifying the delimiter. While I can make it work w ...

What is the best way to create a loop with JSON data?

My challenge is to showcase json data using a loop. I have received the following results, but I am unsure of how to display them with a loop. [ {"latitude":"23.046100780353495","longitude":"72.56860542227514"}, {"latitude":"23.088427701737665"," ...

Tips for sending a structured search query to the findOne() function in MongoDB with Node.js

I have a Restful service built with node.js that takes user input to create a query string for MongoDB. However, whenever I try to pass this query to findone() in MongoDb and call the service, it displays a "query selector must be an object" message in the ...

Managing MUI form fields using React

It seems like I may be overlooking the obvious, as I haven't come across any other posts addressing the specific issue I'm facing. My goal is to provide an end user with the ability to set a location for an object either by entering information i ...

Discover the initial two instances of a specific element within a collection of javascript objects

Within my javascript arraylist, I am currently storing the following elements: list = [ {header: "header1", code: ""}, {label: "label1", price: 10}, {header: "header2", code: ""}, {header: "header3", code: ""}, {header: "header4", code: ""} ] My que ...

What is the best way to restrict datalist options while preserving the "value" functionality?

After finding a creative solution by @Olli on Limit total entries displayed by datalist, I successfully managed to restrict the number of suggestions presented by a datalist. The issue arises from the fact that this solution only covers searching through ...

Mongoose: CastError occurs when querying with an incorrect ObjectId for a nested object

I have the following schema defined: var Topic = new Schema({ text: String, topicId: String, comments: [{type: Schema.Types.ObjectId, ref:'Comment'}] }); var Comment = new Schema({ text: String }); I am working on a RESTFul API that w ...

Eliminate duplicated partial objects within a nested array of objects in TypeScript/JavaScript

I'm dealing with a nested array of objects structured like this: const nestedArray = [ [{ id: 1 }, { id: 2 }, { id: 3 }], [{ id: 1 }, { id: 2 }], [{ id: 4 }, { id: 5 }, { id: 6 }], ] In the case where objects with id 1 and 2 are already grou ...

Receive a notification for failed login attempts using Spring Boot and JavaScript

Seeking assistance with determining the success of a login using a SpringBoot Controller. Encountering an issue where unsuccessful logins result in a page displaying HTML -> false, indicating that JavaScript may not be running properly (e.g., failure: f ...

Managing information retrieved from an asynchronous HTTP request

Here is the script I am using to load an HTML page generated by a node.js server: (function nodeLoader(){ $.ajax({ url: "http://oclock.dyndns.org:8000", method: "get", data: {hk: hk }, success: f ...

Is React Context suitable for use with containers too?

React provides an explanation for the use of Context feature Context in React allows data sharing that can be seen as "global" within a tree of components, like the authenticated user, theme, or language preference. Although this concept works well for ...

Tips for selecting the correct row in a table while making edits using Angular

I'm currently working on an editable table feature, but I'm facing an issue where all rows turn into input fields once I start editing. How can I select only the row that I want to edit by clicking on it? Below is a snippet of my table structure ...

Number failed to trigger ng-disable

I attempted to use ng-disabled attribute to disable a button but was unsuccessful. Below is the HTML snippet: <tr ng-repeat="eachdata in tabledb"> <td>{{eachdata.paid}}</td> </tr> <button class="btn btn-primary" ng-click="p ...

Utilize a jQuery plugin within an AngularJS function

I am using the jQuery plugin select2 and I need to call the select2 function in AngularJS. Although I am aware that I can utilize angular-ui/ui-select, the page design specifically requires the jQuery plugin select2. My goal is to update the value in the ...

The Eclipse IDE is experiencing issues with the functionality of the JavaScript Number class

In my latest project, I decided to create a Dynamic Web Project using the Eclipse IDE 2019-12 along with Apache Tomcat 8.5.55 server. The main functionality of this project is that a user can input integers and receive their sum as an output. To ensure dat ...

Retrieve the value of a dropdown menu that contains multiple selections associated with a single model

My current code generates a calendar entry listing for the courtroom, with each case having a "status" dropdown that is set by the judge post-hearing. I now need to save this data in the database. I have successfully added ng-change which triggers the desi ...