I
I
inscamp2015-02-26 23:15:47
Angular
inscamp, 2015-02-26 23:15:47

Is it possible to use an array of objects as the value of one of the JSON name/value pairs?

There is a json object.

var post = {
"images" : [
  {"img" : "img/1.jpg",
   "img-desc" : "Описание к первому изображению"},
  {"img" : "img/2.jpg",
   "img-desc" : "Описание ко второму изображению"},
   {"img" : "img/3.jpg",
   "img-desc" : "Описание к третьему изображению"}
  ] 
}

In terms of JS syntax, I can declare a json object like this.
However, trying to get to every img and img-desc value with Angular.js ends up with nothing . What is the problem?
<div ng-repeat="image in post.images">
  <img ng-src="{{image.img}}">
  <p>{{image.desc}}</p>
</div>

In addition, it is not possible to remove any specific element. For example like this:
<p>{{post.images[1].img-desc}}</p>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Andrianov, 2015-02-27
@aTwice

Did you add postto $scope?
Everything is working

I
Ivan Koryukov, 2017-11-21
@ZZiliST

First, differences in style must be carried out in classes.

.btn-change-sect {
    display: none;
    border-bottom: 2px solid #ffffff;
}

.active {
   display: block;
   border-bottom: 2px solid #ff7300;
}

Secondly, you should not get attached to the specifics, in your case, when you click, there is only the current element and all the others
$( ".btn-change-sect" ).click(function() {
    // убираем активный стиль со всех подобных элементов
    $( ".btn-change-sect" ).removeClass("active");
    // ставим активный стиль текущему элементу
    $(this).addClass("active");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question