-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-contenteditable.js
More file actions
39 lines (36 loc) · 1.06 KB
/
angular-contenteditable.js
File metadata and controls
39 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*jslint devel: true, browser: true*/
/*global $: true, angular: true*/
var myApp = angular.module("myApp", []);
myApp.directive('contenteditable', function ($parse) {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if (!ngModel) { return false; }
ngModel.$render = function () {
element.html(ngModel.$viewValue || '');
};
element.on('blur keydown change', function () {
scope.$apply(read());
});
function read() {
ngModel.$setViewValue(element.html());
}
}
}
});
function MyCtrl($scope) {
$scope.contacts = [{
first_name: "Sylvain",
last_name: "Kieffer",
email: "sylvain.kieffer@univ-paris13.fr"
},{
first_name: "Laurent",
last_name: "Mernier",
email: "mernier@univ-paris13.fr"
},{
first_name: "Michel",
last_name: "Renauld",
email: "michel.renauld@univ-paris13.fr"
}];
}