Skip to content

Instantly share code, notes, and snippets.

/gist:f93a32fdce77b9416b98 Secret
Created Dec 10, 2014

Embed
What would you like to do?
function EditInPlaceDirective() {
return {
restrict: 'E',
scope: {
value: '=',
fltr: '='
},
template: '<span ng-click="edit()" ng-show="!editing">{{ value | fltr}}</span><input ng-model="value" ng-blur="onBlur()" ng-show="editing"/>',
link: function ($scope, element, attrs) {
var inputElement = element.find('input');
// reference the input element
element.addClass('edit-in-place');
// Initially, we're not editing.
$scope.editing = false;
// ng-click handler to activate edit-in-place
$scope.edit = function () {
$scope.editing = true;
// element not visible until digest complete
// timeout causes this to run after digest
setTimeout(function() {
inputElement[0].focus();
});
};
$scope.onBlur = function() {
$scope.editing = false;
};
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.