ui/forms/bindValues.directive.js

  1. /**
  2. * @module avBindValue
  3. * @memberof app.ui
  4. * @restrict A
  5. * @description handle binding value
  6. *
  7. * The `avBindValue`
  8. */
  9. angular
  10. .module('app.ui')
  11. .directive('avBindValue', avBindValue);
  12. /**
  13. * `avBindValue` directive body.
  14. *
  15. * @param {Object} $compile Angular object
  16. * @param {Object} $timeout Angular object
  17. * @param {Object} events Angular object
  18. * @function avBindValue
  19. * @return {Object} directive body
  20. */
  21. function avBindValue($compile, $timeout, events) {
  22. const directive = {
  23. restrict: 'A',
  24. link
  25. }
  26. function link(scope, element) {
  27. $timeout(() => {
  28. // TODO: for testing purpose only. Works with the sampleForm.module add on
  29. // to make it work ok, we need to add a watch on the element because
  30. // index are always mess up when we add/delete items
  31. element.removeAttr('av-bind-value');
  32. const key = element.attr('data-bind');
  33. element[0].innerText = `{{ ${key} }}`;
  34. $compile(element.context)(scope);
  35. }, 100);
  36. }
  37. return directive;
  38. }