Create a gist now

Instantly share code, notes, and snippets.

(function () {
angular.module('MyModule', [])
.directive(
'autoResizeDirective',
[
'$parse',
function ($parse) {
return {
restrict: 'AC',
scope: true,
link: function ($scope, $elem, $attr) {
var getHeight = function () {
return $elem[0].scrollHeight;
};
var oldHeight = getHeight();
var adjust = function () {
var newHeight = getHeight();
$elem.css('height', newHeight + 'px');
if (oldHeight != newHeight) {
oldHeight = newHeight;
adjust();
}
};
$scope.$watch($attr.ngModel, function () {
adjust();
});
}
};
}
]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment