Error in AngularJS caused by ng-repeat binding

I encountered an issue when trying to bind values using ng-repeat. The error message I'm getting is: TypeError: Cannot read property '#' of undefined

Here's the HTML code:

<ul ng-controller="PeopleCtrl">
    <li ng-repeat="people in peoples">
        {{people.name}}
    </li>
</ul>

And here's the JS code:

var PeopleCtrl = function ($scope) {
$scope.peoples [
    {name: 'Zed'},
    {name: 'Ben'}
];
};

Can anyone provide some insights on why this isn't working? Thank you!

Answer №1

If you want to register your controller, you can use the following code:

var app = angular.module('app', []);
app.controller('PeopleCtrl', ['$scope', function($scope){
    $scope.peoples = [
        {name: 'John'},
        {name: 'Jane'}
    ];
}]);

Check out this JSFiddle link for a live example. (Don't forget to look at [Fiddle Options] in the left menu.)

Here's another example for reference:

See this JSFiddle link with the ng-app tag in the html.

I hope that explanation helps!

Answer №2

Upon reviewing your issue, it appears that your code snippet is structured as follows:

$scope.peoples [
    {name: 'Zed'},
    {name: 'Ben'}
];

However, the correct syntax should be:

$scope.peoples =  [
  {name: 'Zed'},
  {name: 'Ben'}
];

The missing equal sign indicates that you need to assign values to your variable. Remember, = is used for assigning values in JavaScript.

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

Choose the element highlighted in the tab

Are there any CSS or jQuery selectors that specifically target elements that have been focused on using the tab key, similar to how anchor tags and form elements are commonly targeted? ...

At what point does angular2 @output get resolved?

Click on this link Here is the HTML code snippet: <chart [options]="options" (load)="saveGraphInstance($event.context)"></chart> <div (click)="switchGraph()">switch</div> <div (click)="showLoadingForce()">show loadin ...

Updating state in React using the spread operator is not allowed

As a newcomer to React, I've been struggling with using the spread operator to push new elements into an array stored in the state. My aim is to create an array with a sequence of different numbers. Here's the code snippet that I've been wor ...

Tips for designing scrollable overlay content:

I am currently in the process of building a page inspired by the design of Hello Monday. Right now, I have added static content before implementing the parallax effect and auto-scroll. Here is my progress so far: Check out the Sandbox Link One challenge ...

Utilize a directive to showcase information stored within the scope

Struggling to grasp the concept of directives and encountering a bug along the way. To see my example in action, check out the codepen I've created here In my scope called "movies," I have 3 movie titles that I want to display using a directive. va ...

Setting a value to ng-model in AngularJS

I am having some trouble using ng-model with multiple dropdowns. My goal is to have the first select option set to empty, which should then make the rest of the dropdowns also show the empty option. <select ng-model="ddl"> <option></option ...

There is a single occurrence that happens when you click on a label alongside an

How can I change the number of events triggered when clicking a label without directly selecting the input element? Is there a way to achieve this using CSS only, or is it necessary to use JavaScript like document.querySelector('label input')? ...

Show real-time data using Angular6 and GoogleChart

In my project, I am utilizing Angular Cli6, angularfire2, and Firebase to create a timeline using GoogleChart. //GoogleChart.service declare var google: any; export class GoogleChartsBaseService { constructor() { google.charts.load('current&apo ...

During the scraping process with Puppeteer in NextJs, the execution context was terminated, possibly as a result of a navigation

I'm currently developing an application to search for my music on websites that host illegal content, with the intention of requesting its removal later. While working with puppeteer, I encountered an issue when trying to submit a search query and re ...

Updating values dynamically using AJAX within a v-for loop

I'm struggling to figure out how to change the value of an attribute in a v-for loop. For instance, I would like the index to be used as the name of the related product: HTML <div v-for="(index, publication) in publications"> {{ index | nam ...

Node.js: Determine if an object is missing a certain property

My goal is to check if a property 'lessons' (not inherited) is not present in the object. The following conditions all evaluate to true: (typeof obj['lessons'] == undefined) (!(obj.hasOwnProperty('lessons'))) (!(hasOwnPrope ...

Implementing hover effect triggered by keyboard input

Is there a way to create a hover effect on a div when a specific key is pressed on the keyboard using jQuery? <div id="d-up" class="button"></div> Appreciate any help with this! Thank you. ...

Bearer Token CORS preflight request in Web Api 2

I have developed a web application with an AngularJS front-end and a Web Api 2 backend, utilizing bearer tokens for authentication. Everything functions correctly in FireFox and IE, but occasionally in Chrome, the initial login request is pre-flighted. B ...

Unexpected Facts about Refresh Flicker (Tumblr)

I've been attempting to implement a 'random background on refresh' feature for my Tumblr theme. As some may not be aware, Tumblr themes are comprised of HTML alongside embedded CSS and JavaScript. At the moment, I have been utilizing this p ...

attaching a specific column to the right side of the browser window

Hey there! I have a challenge for you. How can I create a table with 4 columns, but only display 3 of them at all times even when resizing the browser? The 4th column should remain hidden, but I still need to be able to scroll to it if needed. Essentially, ...

Storing a boolean value in MongoDB as a string

const myObject = { school: true, address: false }; const myArray = []; myArray.push(myObject); updateSchool(myArray); function updateSchool(thisSchool) { $.ajax ({ type: "POST", url: '/update_school', d ...

What is the mechanism behind sprites in three.js?

I've encountered a problem with my scene that includes numerous sprites and results in a poor frame rate. I attempted to improve performance by reducing sprite resolution and adjusting camera limitations for render distance, but unfortunately, it had ...

Showing dynamic content retrieved from MongoDB in a list based on the user's selected option value

Implementing a feature to display MongoDB documents conditionally on a webpage is my current goal. The idea is for the user to choose an option from a select element, which will then filter the displayed documents based on that selection. For instance, if ...

Convert former function to use async and await system

I need to convert this function to async, but I am facing an issue where the users object obtained from mapping interactions is not returning data in the expected format. When I run the async function on the client side, my values are showing up as nil. Th ...

Ezpay: The CSRF token is not permitted in the header of the Laravel application

After adding the <script> $.ajaxSetup({ headers: { 'csrftoken' : '{{ csrf_token() }}' } }); </script> to the layout blade, every step in the checkout process requires a CSRF token for the POST request. However, during the to ...