javascript - Using ng-options with different objects in AngularJS -


i have array things different objects in it, example 2 differenz objects:

{name: 'book', value: '5',  color: 'blue'} 

and

{name:'pen',  length: '10'} 

now want show these things in droplist using ng-options. can do:

ng-options="(thing.name + ', ' + thing.value + ', ' + thing.color)" thing in things"

if current object book, fine if it's pen, mess. there possibility differentiate between objects want show in droplist or better practice that?

in theory if'ing , else'ing in template data fields come out same, such

ng-options="(thing.name + ', ' + (thing.value ? (thing.value + ", " + thing.color) : (thing.length))" thing in things"

...but that's ugly sin , difficult maintain, if have more 2 irregular object types in things array. you're better off massaging data ahead of time in directive link function generate clean array containing options strings want embedded.

for example if you're looking comma-separated list of fields in each "thing":

scope.mycleanoptions = things.map(function(thing) {     return object.keys(thing).join(", "); // or whatever }); 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -