I have the following html which works and changes the class of the div when the input is changed using the $dirty:
<div class="text-input" ng-class="{typing : (loginForm.test.$dirty || loginForm.test.length > 0)}">
  <span>Username</span>
  <input type="text" name="test" ng-model="user.name" placeholder="test">
  </div>
However when I try and make this into a directive, the ng-class part of it stops working. Can anyone help me to get it working?
Directive:
 angular.module('myApp').directive('smartInputElement',function(){
 return {
   restrict: 'E',
   require: 'ngModel',
   compile: function(element, attrs) {
   element.replaceWith('<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="ngModel" placeholder="'+attrs.name+'"></div>');
   }
 }
});
The html for the directive is:
 <smart-input-element name="username" formName="loginForm" label="Username" ng-model="username"></smart-input-element>
 
     
    