Skip to content

Instantly share code, notes, and snippets.

@saarmstrong
Created October 22, 2013 17:20
Show Gist options
  • Save saarmstrong/7104566 to your computer and use it in GitHub Desktop.
Save saarmstrong/7104566 to your computer and use it in GitHub Desktop.
example of click to edit directive module
var cms = angular.module('cms', []);
cms.directive("clickToEdit", function() {
var editorTemplate = $j('#editTemplate').html();
return {
restrict: "A",
replace: true,
template: editorTemplate,
scope: {
value: "=clickToEdit",
idx: '@'
},
controller: function($scope, $http, $templateCache) {
$scope.view = {
editableValue: $scope.value,
editableIdx: $scope.idx,
editorEnabled: false
};
$scope.enableEditor = function() {
$scope.view.editorEnabled = true;
$scope.view.editableValue = $scope.value;
};
$scope.disableEditor = function() {
$scope.view.editorEnabled = false;
};
$scope.save = function() {
$scope.value = $scope.view.editableValue;
$scope.disableEditor();
console.log('Saved');
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment