Skip to content

Instantly share code, notes, and snippets.

@mattlanham
Last active May 19, 2016 07:55
Show Gist options
  • Save mattlanham/9738979 to your computer and use it in GitHub Desktop.
Save mattlanham/9738979 to your computer and use it in GitHub Desktop.
Really simple directive for http://vitalets.github.io/x-editable/, created this because i wanted to use the popover, and not the inline version provided by the existing angularJS directive. It's really simple to use, just add 'editable' to your modules, then use like: <h2 ng-model="form.name" editable></h2> you can also pass through options i.e.…
(function() {
"use strict";
angular.module("editableModule", ['ng']).directive("editable", function($timeout) {
return {
restrict: "AE",
scope: true,
require:"ngModel",
link: function(scope, element, attrs, ngModel) {
element.editable({
success: function(response, newValue) {
$timeout(function() {
ngModel.$setViewValue(newValue);
ngModel.$render();
});
}
});
scope.$watch(attrs.ngModel, function(newValue) {
element.editable('setValue', newValue);
});
}
};
});
}).call(this);
@mattlanham
Copy link
Author

Spot on, i've updated the gist accordingly

@PatrickJS
Copy link

also if you include jquery and it's plugins before angular you element should have . editable() so you don't have to wrap it again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment