Last active
May 19, 2016 07:55
-
-
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.…
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
(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); |
Spot on, i've updated the gist accordingly
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
I would change your watch to
I'm not sure what you're using
scope.editable
for. You're also creating an isolated scope but not using it other thanscope.editable
. You can set the scope to true if you don't plan on using it but want the scope isolated