Search code examples
angularjsjsoninputto-json

ngTagsInput get and parse data from database


When I use ngTagsInput before send to database I do:

angular.toJson($scope.tags);

When I make get I receive something like this in my scope {{}}:

[{"text":"abc"},{"text":"cba"},{"text":"tag"}]

What can I do to show my tags like this:

abc, cba, tag

Solution

  • In the template:

    <span ng-repeat="(key, value) in tags"><span ng-if="!$first">, </span><span>{{value.text}}</span></span>
    

    Or with Underscore in code:

    var str = _.pluck(list, 'text').join(', ')
    

    Other options here: Show an aggregated list in angularjs