| function EditInPlaceDirective() { | |
| return { | |
| restrict: 'E', | |
| scope: { | |
| value: '=' | |
| }, | |
| template: '<span ng-click="edit()" ng-show="!editing">{{ value | currency}}</span><input ng-model="value" ng-blur="onBlur()" ng-show="editing"></input>', | |
| 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