更新时间:2023-02-27 08:10:39
编辑
这是一个基于 Angular 文档中的示例的示例,该示例仅使用 ng-repeat
.由于 ng-repeat
为每次迭代创建了一个新的作用域,所以这应该不是问题.
<html ng-app="form-example2"><头><script src="http://code.angularjs.org/1.0.5/angular.min.js"></script><脚本>angular.module('form-example2', []).directive('contenteditable', function() {返回 {要求:'ngModel',链接:函数(范围,榆树,属性,ctrl){//查看 ->模型elm.bind('blur', function() {范围.$应用(函数(){ctrl.$setViewValue(elm.html());});});//模型 ->看法ctrl.$render = function() {elm.html(ctrl.$viewValue);};//从 DOM 加载初始值ctrl.$setViewValue(elm.html());}};});头部><身体><div ng-repeat="i in [1, 2, 3]"><div contentEditable="true" ng-model="content" title="点击编辑">一些</div><pre>model = {{content}}</pre>