D. Wilson
D. Wilson

Reputation: 136

Angularjs - dynamic elements/templates

I'm trying to figure out the best way to create dynamic elements.

Basically, i have a multi-select list, eg...

Item 1
Item 2
Item 3

Once selected either one or more, it needs to generate elements for these selections such as...

Item 1
Name: ....
Quantity: ....

add insert to the view. Would i need to define all these hidden elements in the view?

Or should i use a directive? If you could point me in the right direction that would be appreciated!

Upvotes: 0

Views: 21

Answers (1)

Fissio
Fissio

Reputation: 3758

Just use a combo of ng-repeat and ng-show/ng-if.

<div ng-repeat="item in list" style="margin-top:10px">
    <input type="checkbox" ng-model="item.selected">Item {{$index + 1}}
    <div style="margin-left:30px" ng-show="item.selected">
        <div>Name: {{item.name}}</div>
        <div>Quantity: {{item.quantity}}</div>
    </div>
</div>

https://plnkr.co/edit/Mvydk1CMG8PM7LTmI57R?p=preview

Upvotes: 1

Related Questions