I'm using jQuery tags input library in my angularJS project. On frontend side, I able to add the tags, but when I retrieve the texts for that input. It contains spaces in between the values. I tried to use replace function on the string variable, it doesn't work.
HTML
<input id="news_tags" data-js-tags-input="" type="text" name="example-tags1" value="" ng-model="news.tags"
class="form-control ng-pristine ng-untouched ng-valid ng-empty" data-tagsinput-init="true" style="display: none;">
<div id="news_tags_tagsinput" class="tagsinput" style="width: 100%; min-height: 36px; height: 36px;">
<span class="tag">
<span>tag1 </span>
<a href="#" title="Removing tag">x</a>
</span>
<span class="tag">
<span>tag2 </span>
<a href="#" title="Removing tag">x</a>
</span>
<div id="news_tags_addTag">
<input id="news_tags_tag" value="" data-default="Add tag" style="color: rgb(102, 102, 102); width: 68px;">
</div>
<div class="tags_clear"></div>
</div>
Controller
var tags = jQuery("#news_tags_tagsinput .tag span").text().trim();
alert((typeof tags)); // String
alert(tags.replace(" ", ",")); // tag1 tag2
alert(tags.replace(" ", ",")); // tag1 tag2
alert(tags.replace(" ", ",")); // tag1 tag2
alert(tags.replace(" ", ",")); // tag1 tag2
Output
tag1 tag2
Instead Of
tag1,tag2