0

I am recieving the following error while trying to bind values with ng-repeat TypeError: Cannot read property '#' of undefined

html:

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

JS:

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

Any ideas why this isn't working? Thanks

2
  • Are you registering the controller? Commented Nov 28, 2014 at 2:37
  • 1
    Put your code in jsFiddle or plunker and post the URL. Commented Nov 28, 2014 at 2:46

2 Answers 2

1

You can register your controller like this:

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

http://jsfiddle.net/eL3okv5w/ (Note the [Fiddle Options] in the left menu.)

And the follow is another example

http://jsfiddle.net/dakra/U3pVM/ (Note ng-app tag in html)

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

0

In your problem you have something like

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

but it should looks like

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

You are missing equal sign you need to assign the values to your variable in order to use it = is used to assign values to your variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.