我正在研究 angularjs,我想编写一个自定义的“可编辑”指令,它可以使普通的 html 元素“可编辑”:

当用户点击它时,它会显示一个文本输入或文本区域让用户编辑内容,此外还有一个“更新”和“取消”按钮。用户可以点击“更新”按钮或按“Ctrl+回车”提交修改的内容,或点击“取消”或按“退出”取消修改。

“可编辑”签名如下所示:

<div editable
     e-trigger="click|dblclick"       /* use click or dblclick to trigger the action */
     e-update-url="http://xxx/xxx"    /* when submitting, the data will PUT to this url */
     e-singleline="true|false"        /* if ture, use text input, otherwise textarea */
     ng-model="name">                 /* the corresponding model name */
{{name}}
</div>

我在这里创建了一个现场演示: http://jsfiddle.net/Freewind/KRduz/ ,你可以更新它。

最佳答案

我自己是 Angular 的新手,希望你能用你的 fiddle 得到一个有效的例子。同时,John Lindquist 有一个很棒的视频,他解释了如何创建 Markdown 标签以嵌入编辑器。其中详细介绍了如何使用 Angular 指令制作可编辑和预览区域。

  • Part 2
  • Part 1
  • 关于angularjs - 使用 angularjs 编写自定义 "editable"指令,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11176610/

    10-09 23:34
    查看更多