Search code examples
angularjsng-tags-input

ng-tags-input, storing tags data as a string array


I'm using ng-tags input, and the data I get after populating a line is an array of object, each with one 'text' string field like so

[{"text":"egon"},{"text":"peter"},{"text":"raymond"},{"text":"winston"}]

Is there a way to store the data as an array of strings instead? like

["egon", "peter", "raymond", "winston"]

Solution

  • ngTagsInput only works with arrays of objects. You can easily extract an array of strings out of an array of objects, though:

    $scope.tagsString = $scope.tags.map(function(tag) { return tag.text; });
    

    Update

    It took some time, but ngTagsInput offers now basic support for array of strings. Starting in v3.2.0, the following is possible:

    <tags-input ng-model="tags" use-strings="true"></tags-input>
    

    Plunker

    Better late than never, I guess.