angularjs - Comma Separated <p> angular -
i have pretty basic scenario (somewhat new angular). trying convert json:
[ {'name': 'nick'}, {'name': 'david'}, {'name': 'john'}, ]
to:
<p>nick,david,john</p>
but can not figure out how generate single "p." how call ng-repeat inside of <p>
<p ng-repeat="item in menuitems">{{item.name}}</p>
one thing helpful creating "map" filter, so:
mymodule.filter('map', function() { return function(input, propname) { return input.map(function(item) { return item[propname]; }); }; });
that's simple case of mapping named property, make more fancy , understand dot notation, etc. this, in view can do:
<p> {{(menuitems | map:'name').join(',')}} </p>
because map filter returns array, has built-in join method in javascript.
Comments
Post a Comment