user4293838
user4293838

Reputation:

AngularJS ng-repeat binding error

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

Upvotes: 0

Views: 69

Answers (2)

madu
madu

Reputation: 354

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

Upvotes: 0

Teddy
Teddy

Reputation: 797

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.

Upvotes: 1

Related Questions