JSFiddle - React, Tailwind, and code Playground
HTML
<html ng-app="myApp">
<body ng-controller="testCtrl">
<div in-tags>{{tags}}</div>
</body>
</html>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('testCtrl',
function testCtrl($scope){
$scope.tags = 'уголь патриарх трансплантация';
});
myApp.directive('inTags',function($compile){
return{
link: function(scope, element, attrs, controller){
element.html(devide(element.text()));
$compile(element.contents())(scope);
}
};
function devide(text){
var tags = text.split(/\s+/),
answer = '',
i = 0;
tags.forEach(function(item){
i++;
answer += '<span class="tag">'+i+' '+item+'</span></br>';
});
return answer;
}
});