0

I am quite new to AngularJS and I am currently trying to figure out how to best approach this functionality:

I am looking for a way where I have something along the lines of <span editable>I am a text</span>, and when the user clicks on it, it becomes editable (eg. <input type="text">) until the element loses focus, at which point it should flip back to its original <span editable>...</span> with the new value. Furthermore, this is likely not static text but bound to a model.

I am thinking this should be doable with directives, but I've hit a road block along the line as to how such a directive would actually work.

app.directive('editable', function() {
    return function(scope, element, attrs) {
        element.bind('click', function () {
            // something.
        });
    }
})

Can anyone provide me with guidance or a solution to this?

Thanks in advance,
- Manny

2
  • This may help chandermani.blogspot.in/2012/12/angularjs-and-inplace-edit.html Commented Feb 20, 2014 at 12:40
  • You are a gentleman and a scholar, Chandermani. This seems to cover what I was looking for. If you add it as an answer below, I can mark it as a solution, so you get the credit, fame and glory :) Commented Feb 20, 2014 at 12:56

1 Answer 1

1

How i did this was to create a directive that could be applied to any html element. It hides the standard element and shows a text field when you click in it. Then it changes it back to the origninal element when you move away from the field.

More details here

and here is the companion fiddle

http://jsfiddle.net/cmyworld/6gMXL/

You can use it like

    <h1>
      <editable model="heading" on-delete="" defaultval="Default val">
    </h1>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.