JSFiddle - React, Tailwind, and code Playground
by indatawetrust
HTML
<html ng-app="app">
<body ng-controller="tagsController">
<input type="text" ng-model="text">
<br>{{ tags }}
</body>
</html>
JavaScript
var app = angular.module('app',[]);
app.controller('tagsController',function($scope){
$scope.text = '#javascript #angularjs';
$scope.tags = [];
$scope.$watch('text',function(_new,_old){
$scope.tags = [];
_new.replace(/(#[a-zA-Z0-9]+)/igm,function(data){
if($scope.tags.indexOf(data) == -1){
$scope.tags.push(data);
}
});
$scope.tags.forEach(function(tag){
var rgx = new RegExp(tag,'igm');
if(_new.match(rgx) == null){
$scope.tags.splice($scope.tags.indexOf(tag),1);
}
});
});
});