0

I'm able to insert one image into a div using angular.js.But unable to insert three images into a div.Can anyone please help me out regarding this issue ...

My js code:

angular.module('Admin', [])
.controller('Home', function($scope) {

  $scope.imageSources = [];

    for (var i = 0; i < 3; i++) {
         $scope.imageSources .push('images/open.jpg');
         $scope.imageSources .push('images/new.jpg');
         $scope.imageSources .push('images/save.jpg');

    }

});

My html code:

<div id="divone" class="subdiv">
                <div>
                <img width=176 height=99 ng-repeat="imageSource in imageSources track by $index" ng-src="{{imageSource }}">
  </img>
                </div>

            </div>
3
  • Why do you have a for loop, you're essentially pushing each of those URLs every times, making 9 entries to your array. Also what does the class .subdiv look like? I was able to recreate this with no issue in a codepen. - codepen.io/jusopi/pen/EPNgpz Commented Dec 29, 2015 at 6:07
  • There was some issue in loading angular.js plugin.I had removed the for loop .Now it's working fine for me Commented Dec 29, 2015 at 6:11
  • But I'm getting all the images vertically.But I want to display all the three images horizontally.How can I do this ? Commented Dec 29, 2015 at 6:16

1 Answer 1

1

I don't understand why you are using the for loop. Can you explain?

Check out the following code -

angular.module('Admin', [])
.controller('Home', function($scope) {

  $scope.imageSources = [];

    $scope.imageSources.push('http://www.imageno.com/thumbs/20151223/af9znxap7p6a.jpg');
     $scope.imageSources.push('http://laurencebonvin.com/wp-content/uploads/2015/10/images-3-200x120.jpg');
     $scope.imageSources.push('http://thumbs.photo.net/photo/18041438-sm.jpg');

});
img{
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="Admin">
    <div ng-controller="Home" id="divone" class="subdiv">
      <div>
        <img width=176 height=99 ng-repeat="imageSource in imageSources track by $index" ng-src="{{imageSource }}" />
      </div>
    </div>
  </body>

UPDATE:

And add display: block property to your image for displaying image vertically.

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

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.