-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-setcontacts.js
More file actions
42 lines (38 loc) · 1.21 KB
/
angular-setcontacts.js
File metadata and controls
42 lines (38 loc) · 1.21 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
40
41
42
/*jslint devel: true, browser: true*/
/*global $: true, angular: true*/
var myApp = angular.module("myApp", []);
function log (text) { console.log(text); }
myApp.directive("setContact", function () {
return function (scope, el, attrs) {
el.on('click', function () {
var form = $(attrs.setContact);
if (form.length != 1) {
console.log(attrs.setContact + " ne pointe pas vers un unique élément.");
return false;
}
$.each(scope.contact, function (key, value) {
// on n'utilise pas les $$hashKey
if (!/\$/.test(key)) {
form.find("input[name=" + key + "]").attr("value", value);
}
});
});
}
});
function MyCtrl($scope) {
'use strict';
$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"
}];
$scope.contact = $scope.contacts[0];
}