Mam stronę HTML z formularzem i liczbą pól wejściowych i karuzeli. Na dole formularza znajduje się button
do Dodaj kolejny cytat .. Zasadniczo kopia pól wejściowych powyżej (całość class="quote"
).Po kliknięciu wstaw inny szablon
HTML:
<form name="myForm">
<div class="quote">
<p>Enter the fields below</p>
<input type="text" ng-model="'firstname'+{{$index}}" />
<input type="text" ng-model="'surname'+{{$index}}" />
<input type="text" ng-model="'postcode'+{{$index}}" />
<input type="text" ng-model="'productid'+{{$index}}" />
<input type="text" ng-model="'price'+{{$index}}" />
<div class="carousel">
<img src="/assets/img/chair.jpg" alt="" />
<img src="/assets/img/spoon.jpg" alt="" />
<img src="/assets/img/table.jpg" alt="" />
<img src="/assets/img/tap.jpg" alt="" />
</div>
<button class="add-another" ng-click="addAnother()">Add another quote</button>
</div>
</form>
co próbuję osiągnąć to, że w dniu kliknięcia add-another
, wstawić kopię class = "quote" gdzie {{$ index}} jest również zwiększany o kliknięcia. Chodzi o to, aby umożliwić nieograniczoną dodawanie wierszy ... więc wynikiem będzie:
<form name="myForm">
// First quote ////////////////
<div class="quote">
<p>Enter the fields below</p>
<input type="text" ng-model="'firstname'+{{$index}}" />
<input type="text" ng-model="'surname'+{{$index}}" />
<input type="text" ng-model="'postcode'+{{$index}}" />
<input type="text" ng-model="'productid'+{{$index}}" />
<input type="text" ng-model="'price'+{{$index}}" />
<div class="carousel">
<img src="/assets/img/chair.jpg" alt="" />
<img src="/assets/img/spoon.jpg" alt="" />
<img src="/assets/img/table.jpg" alt="" />
<img src="/assets/img/tap.jpg" alt="" />
</div>
<button class="add-another" ng-click="addAnother()">Add another quote</button>
</div>
// Second quote ////////////////
<div class="quote">
<p>Enter the fields below</p>
<input type="text" ng-model="'firstname'+{{$index}}" />
<input type="text" ng-model="'surname'+{{$index}}" />
<input type="text" ng-model="'postcode'+{{$index}}" />
<input type="text" ng-model="'productid'+{{$index}}" />
<input type="text" ng-model="'price'+{{$index}}" />
<div class="carousel">
<img src="/assets/img/chair.jpg" alt="" />
<img src="/assets/img/spoon.jpg" alt="" />
<img src="/assets/img/table.jpg" alt="" />
<img src="/assets/img/tap.jpg" alt="" />
</div>
<button class="add-another" ng-click="addAnother()">Add another quote</button>
</div>
// Third quote ////////////////
// Fourth quote ////////////////
// Fifth quote ////////////////
</form>
Oto bardzo szybka próba z plunker: http://plnkr.co/edit/bl1BMkLbeT2tr907lJYK?p=preview
Zanotuj Dodaj kolejny cytat przycisk robi praca, kliknij na Dodaj nowy cytat u góry, aby wstawić nowe wiersze.
Bardzo chciałbym użyć animacji hide/show jQuery, gdy wiersze zostaną dodane/usunięte.
Mimo wielu błędów!