New at Angular, I spent 2 hours searching my error, helped by a few docs and watching the already existing posts but nothing to do..
I'm just hard declaring an object array and try to loop through it:
Code:
angular.module('MyAppModule', [ ])
.controller('GreetsController', ['$scope', function ($scope) {
$scope.name = prompt('What\'s your name ?');
}])
.controller('ListController', ['$scope', function ($scope) {
$scope.personNb = this.persons.length;
$scope.persons = [
{
image: 'images/images(1).jpg',
name: 'John Doe',
age: 23
},
{
image: 'images/images.jpg',
name: 'John Doe',
age: 23
},
{
image: 'images/téléchargement.jpg',
name: 'John Doe',
age: 23
},
{
image: 'images/téléchargement(1).jpg',
name: 'John Doe',
age: 23
}
];
}]);
Html:
<div ng-controller="GreetsController">
<h1>Coding with AngularJs</h1>
<h2 ng-show="name">{{"Welcome " + name + " !"}}</h2>
</div>
<div ng-controller="ListController" ng-repeat="person in persons">
<h3>{{person.name}}</h3>
<h3>{{person.age}}</h3>
</div>
{{ListController.persons[0].age}}
<h3 ng-show="{{ListController.person_nb}}">There is a total of {{ListController.person_nb}} register</h3>
I didn't captured it but all the scripts are includes and I add 'MyAppModule' in the depedencies array of app.js
ng-controllerandng-repeaton the same element, since that element is the one that is repeated. 2. you are trying to callListController.person_nbin HTML, which will not work. 3. yourng-showis taking a number and checking true/false for it, which makes no sense. 4. you try to get a length before you even have an array, and you are trying to get the length of an array onthis, instead of$scope.