Angular: Empty Fiddle

http://angularjs.org/

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
    <input ng-model="myVar" class="demo" />
    <br /><br />
    {{myVar}}
</div>

JavaScript

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.myVar = '';
}

myApp.directive('demo', function() {
    return {
        require: 'ngModel',
        restrict: 'EACM',
        link: function(scope, element, attrs, modelCtrl) {
            setAndRender(modelCtrl, "12345");
            modelCtrl.$parsers.push(function(inputValue) {
                return logic(inputValue, modelCtrl);
            });
        }
    };
});

function logic(inputValue, modelCtrl) {
    var returnValue;
    if (inputValue.length > 5) {
        returnValue = String(inputValue).substring(1,6);
    }
    else {
        returnValue = inputValue;
    }
    setAndRender(modelCtrl, returnValue);
    return returnValue;
}

function setAndRender(mc, val) {
    mc.$setViewValue(val);
    mc.$render();
}