12
rated 0 times
[
13]
[
1]
/ answers: 1 / hits: 34129
/ 9 Years ago, sun, april 19, 2015, 12:00:00
I'm doing something wrong yet I cannot see what (this is probably due to my low AngularJS skills).
I have a simple ng-repeat in my HTML:
<ul>
<li ng-repeat=fot in fotografia><img src={{fot.path}}></li>
</ul>
and here is my app.js:
myApp.controller('homeController', function($scope) {
// fotografia = []; is here only because I get an error otherwise,
// which means my later for loop can't access the $scope.fotografia
fotografia = [];
$scope.fotografia = [
{path:'img/fotografia/fot_1.jpg'},
{path:'img/fotografia/fot_2.jpg'}
];
// I want to add more images with this:
for(var i=0; i<5; i++) {
fotografia.push({
path: 'img/fotografia/fot_'+[i]+'.jpg'
});
}
});
Ng-repeat works fine with the 2 images I already have in my array (fot_1.jpg, fot_2.jpg). The loop is the the problem. How do I go about pushing more items into my array?
More From » angularjs