Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.0rc12.js"></script>
<div ng-init="editable = false; name='Superhero'">
Your name is <b ng-hide="editable" ng-click="editable=true">{{name}}.</b>
<input ng-show="editable" ng-hasfocus="editable" ng-model="name"></input>
Click to edit it!
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.directive('ngHasfocus', function() {
return function(scope, element, attrs) {
scope.$watch(attrs.ngHasfocus, function (nVal, oVal) {
if (nVal)
element[0].focus();
});
element.bind('blur', function() {
scope.$apply(attrs.ngHasfocus + " = false");
});
element.bind('keydown', function (e) {
if (e.which == 13)
scope.$apply(attrs.ngHasfocus + " = false");
});
}
});