Skip to content

Instantly share code, notes, and snippets.

@tmarcus87
Created November 18, 2016 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmarcus87/cd1fc1f89500f700db129defbc4c1482 to your computer and use it in GitHub Desktop.
Save tmarcus87/cd1fc1f89500f700db129defbc4c1482 to your computer and use it in GitHub Desktop.
(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