1

var myApp = angular.module('myApp', []);

myApp.controller('ng-angular-pictures', function() {
  console.log('inside of container');
  var vm = this;
  vm.pictures = ['images/acapulco_2.jpg', 'images/acapulco.jpg', 'images/Chihuahua_sitting.jpg'];


  console.log(vm.pictures);

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>angular-weekend-4-challenge</title>
  <link rel="stylesheet" href="styles/style.css">
  <script src="vendors/angular.min.js" charset="utf-8"></script>
  <script src="scripts/script.js" charset="utf-8"></script>
</head>

<body ng-app='myApp'>
  <h1>angular-weekend-4-challenge</h1>
  <div class="container" ng-controller='ng-angular-pictures as ai'>


  </div>
</body>

</html>

I am new to Angular. I come from jquery. I want to somehow loop through my vm.pictures array. In my html controller scope, I want to do the looping and show my pictures in the DOM.

2 Answers 2

2

you can use ng-repeat something like vm.pictures

<div ng-repeat="pic in ai.pictures"><img ng-src="{{pic}}"/></div>
Sign up to request clarification or add additional context in comments.

2 Comments

Well it did loop trough my array and added the 3 images on the DOM. It didn't work at first, but i changed vm.pictures to ai.pictures, but the images arent showing in the dom. It is just the squares
here do i do that @Abdoutelb
1

You can also achieve it this way if you want to boost performance

<div ng-repeat="pic in ::ai.pictures track by $index"><img ng-src="{{::pic}}"/></div>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.