hasane has hasane has - 1 month ago 23
AngularJS Question

how to use md-chips with ng-repeat (key, value)

I'm trying to use md-chips with ng-repeat when using (key, value) flavor here is an example of what I'm trying to do :


<md-content class="md-padding" layout="column" ng-repeat="(key,value) in items">
<md-chips ng-model="???" name="fruitName" readonly="true" md-removable="" md-max-chips="5">
<md-chip-template>
<strong>{{key}} :{{value}}</strong>
</md-chip-template>
</md-chips>
</md-content>



(I don't know what to do in the
ng-model
).

thank you in advance

edit

here is my json data for example {'a':'1','b':'2','c':'3'}



<md-chips class="custom-chips" ng-model="ctrl.vegObjs" readonly="true">
<md-chip-template>
<span>
<strong> {{$chip}} </strong>
</span>
</md-chip-template>
</md-chips>




by using this code I can have {"a":"1"} {"b":"2"} {"c":"3"}, but it's not exactly what I want.

Answer

Try this

<md-chips ... ng-model="_key" ng-init="_key = [key]" ...></md-chips>

Working codepen

Comments