Created
April 3, 2015 22:51
-
-
Save aruss/5ba0fa16b0045369617c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function(app, $, undefined) { | |
app.directive('uiEditable', function($sce) { | |
return { | |
restrict: 'A', | |
require: '?ngModel', | |
link: function(scope, element, attrs, ngModel) { | |
if (!ngModel) { | |
return; | |
} | |
ngModel.$render = function() { | |
return element.html(ngModel.$viewValue); | |
}; | |
element.bind('blur keyup change', function() { | |
if (ngModel.$viewValue !== $.trim(element.html())) { | |
return scope.$apply(read); | |
} | |
}); | |
function read() { | |
return ngModel.$setViewValue($.trim(element.html())); | |
}; | |
} | |
}; | |
}); | |
})(angular.module('app'), angular.element); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment