JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="app" ng-controller="example">
<select ng-model="type" ng-options="k as v for (k,v) in { h1: 'Large', h2: 'Medium', h3: 'Small' }"></select>
<h1 change-type>Text</h1>
<div>{{ type }}</div>
</div>
JavaScript
angular.module('app', [])
.controller('example', function ($scope) {
$scope.type = 'h2';
})
.directive('changeType', function ($compile) {
return {
restrict: 'A',
link: function (scope, element, attributes) {
scope.$watch('type', function () {
var attrs = element[0].attributes;
var newElement = $('<' + scope.type + '>').text(element.text());
for (var i = 0; i < attrs.length; i++) {
newElement.attr(attrs.item(i).name, attrs.item(i).value);
}
element.replaceWith(newElement);
$compile(element.contents())(scope);
});
}
};
});