I have the following html which works and changes the class of the div when the input is changed using the $dirty:
Here is a plunker: http://plnkr.co/edit/3AFOHZFgExZKHjnd3gb0?p=preview
When you replace an element inside the compile function you should:
Directive:
app.directive('smartInputElement', function($compile) {
return {
restrict: 'E',
priority: 1001,
terminal: true,
compile: function(tElm, attrs) {
var template = angular.element(
'<div class="text-input" ng-class="{typing : (' + attrs.formname + '.' + attrs.name + '.$dirty || ' + attrs.formname + '.' + attrs.name + '.length > 0)}">' +
'<span>' + attrs.label + '</span>' +
'<input type="text" name="' + attrs.name + '" ng-model="' + attrs.ngModel + '" placeholder="' + attrs.name + '">' +
'</div>');
tElm.replaceWith(template);
var fn = $compile(template);
return function(scope) {
fn(scope);
};
}
};
});