This jsFiddle explains it all
My code separates hashtags, e.g., #riots = <span class="hashtags">#riots</span>
but it's being printed as plaintext instead of html. What am I doing wrong?
function formCtrl($scope){
$scope.$watch(function() {
$scope.description = "Wow, it's crazy over here! #baltimore #riots";
$scope.vidTags = $scope.description.match(/(^|\s)(#[a-z\d-]+)/ig);
$scope.desc = $scope.description.replace(/(^|\s)(#[a-z\d-]+)/ig, "$1<span class='hashtag'>$2</span>");
})
}
#description {
width: 300px;
height: 3em;
}
.hashtag {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-controller="formCtrl">
<textarea ng-model="description" id="description"></textarea>
<br />
vidTags: {{vidTags}}
<br />
desc: {{desc}}
<br />
</div>