Adding style to angular

I have the following code snippet in my html:

<p>Tags: {{source.tags}}</p>

This is the processed html:

mq-server queue republish purge

This value comes from a field in my object:

'tags': 'mq-server queue republish purge'

I want to add a style to each separated by a spatial word, in the best words like tags, I like the level information in bootstrap, who has an idea how to achieve this?

+4
source share
2 answers

You can split the string into separate words and use ng-repeat to display them within a range with label classes

<span class="label label-default" ng-repeat="tag in source.tags.split(' ')">{{tag}}</span>
+3
source

, ng-repeat , .

:

$scope.source.tagsArray = $scope.source.tags.split(" ");

<p>Tags: 
    <span ng-repeat="tag in source.tagsArray" class="label label-info">
        {{tag}}
    </span>
</p>
+2

All Articles