G
G
GaserV2016-03-28 22:12:53
Angular
GaserV, 2016-03-28 22:12:53

Why does ng-click + ng-repeat change the values ​​in each repeat, and not in the current one?

Tell. Why does ng-click + ng-repeat change the values ​​in each repeat, and not in the current one? I need, for example, when I click, only the current answer to the question is revealed, and not everywhere. And another problem. If there is only one question, then it is hidden, and by clicking on it, the answer to it is revealed. But if there are two or more, then they are all open at once ... What is it? How to fix? Tell me please. I've been sitting here all evening...

<section class="content">
  <div class="section-header">
    <div class="section-title">
      Акции<span class="arrow-right"></span><span class="back-link hidden right"><  Назад</span>
    </div>
    <div ng-show="showClients" class="section-btn-create">
      <button class="btn1" onclick="showAddForm()">Добавить</button>
    </div>
  </div>
  <div class="signs">	
    <div ng-repeat="sign in signs" class="sign">	
      <div ng-click="sign.opened = !sign.opened" class="options-title">СКИДКА 20.16%</div>
      <div ng-class='{"sign_opened":sign.opened}' class="signs-content">
        <form ng-submit="updateSign()">
          <input ng-model="formData.title" class="btn1" name="title" type="text" placeholder="{{ sign.title }}"><br>
          <input ng-model="formData.subtitle" class="btn1" name="subtitle" type="text" placeholder="{{ sign.subtitle }}"><br>
          <input ng-model="formData.offdate" class="btn1" name="off-date" type="text" placeholder="{{ sign.odate }}"><br>
          <textarea ng-model="formData.shortdesc" class="btn1" name="short-desc" placeholder="Краткое описание"></textarea><br>
          <textarea ng-model="formData.fulldesc"  class="btn1" name="full-desc" id="" placeholder="Полное описание"></textarea><br>
          <label class="label-input-file" for="preview-image">Превью изображение:</label>
          <input ng-model="formData.previewimage" id="preview-image" class="input-file" name="preview-image" type="file"><br>
          <label class="label-input-file" for="full-image">Полное изображение:</label>
          <input ng-model="formData.fullimage" id="full-image" class="input-file" name="full-image" type="file"><br>
          <label class="label-input-file work-examples">Примеры работ:</label>
          <span ng-click="createField(sdf)" class="add-ico">+</span><br>
          <div ng-repeat="field in sign.fields">
            <label class="label-input-file" for="example-image">Изображение {{ field.id }}</label>
            <input ng-model="formData.exampleimage" id="example-image" class="input-file" name="example-image{{ field.id }}" type="file"><br>	
          </div>
          <input class="submit-input" type="submit" value="Изменить">
        </form>
      </div>
    </div>
  </div>
</section>

$scope.signs = 
  [
    {

      title: "title",
      subtitle: "subtitle",
      stext: "text",
      ftext: "text",
      odate: "23.12.2016",
      fields: [{id: "1"},{id: "2"}]

    }
];

  $scope.createField = function(sdf) {
      var lastId = sdf.length;
      var newId = lastId + 1   
      
      sdf.push({'fields.id' : newId});
      console.log(sdf)
  };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rakro, 2016-03-29
@rakro

You are pushing into the fields array. Output it in every repeat. the same array. What behavior is expected? If you want the fields array to be unique to each sign, put it in sign, not scope.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question