JavaScript How to bind an td contenteditable value to ng-model

Hi i have the following td element:

<td ng-model="name" contenteditable='true'></td>

Is there anyway I can pass this ng-model value from the contenteditable td to my controller? Thanks in advance guys

Answer:1

Binding to contenteditable isn't built in, but you can write a simple directive that will accomplish the task.

app.directive("contenteditable", function() {
  return {
    restrict: "A",
    require: "ngModel",
    link: function(scope, element, attrs, ngModel) {

      function read() {
        ngModel.$setViewValue(element.html());
      }

      ngModel.$render = function() {
        element.html(ngModel.$viewValue || "");
      };

      element.bind("blur keyup change", function() {
        scope.$apply(read);
      });
    }
  };
});

Take note, however, that in Internet Explorer, contenteditable cannot be applied to the TABLE, COL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, or TR elements directly; a content editable SPAN or DIV element would need to be placed inside the individual table cells (See http://msdn.microsoft.com/en-us/library/ie/ms533690(v=vs.85).aspx).

Answer:2

i have a little problem with my drop menu function. what i want to have is that after clicking a menu tab for the second time it visibility should be hidden. here is my code.... HTML:- <nav ...

i have a little problem with my drop menu function. what i want to have is that after clicking a menu tab for the second time it visibility should be hidden. here is my code.... HTML:- <nav ...

  1. creating drop down in excel
  2. creating drop down menu in excel
  3. creating drop down in google sheets
  4. creating drop down in word
  5. creating drop down list excel
  6. creating drop down in excel 2016
  7. creating drop down list
  8. creating drop down filters in excel
  9. creating drop down in pdf
  10. creating drop down menu in wordpress
  11. creating drop down list in access
  12. creating drop down selection in excel
  13. creating drop down in excel 2013
  14. creating drop down in excel 365
  15. creating drop down menu in squarespace
  16. creating drop down in excel with color
  17. creating drop down list in html
  18. creating drop down in google docs
  19. creating drop down box in word
  20. creating drop down list in excel 2013

I currently have a radial progress bar like a 'solid' border and I'd like to have a radial progress bar with sections (like a 'dashed' border but with more control on it). What I'm looking for : ...

I currently have a radial progress bar like a 'solid' border and I'd like to have a radial progress bar with sections (like a 'dashed' border but with more control on it). What I'm looking for : ...

I'm following this awesome blog and there is a simple example of generators with sending a value for the .next() method: var answers = [ `It is certain`, `It is decidedly so`, `Without a doubt`, `...

I'm following this awesome blog and there is a simple example of generators with sending a value for the .next() method: var answers = [ `It is certain`, `It is decidedly so`, `Without a doubt`, `...

  1. python generator input value

When I'm trying to do object-oriented pure JS with private methods, I frequently do the following (function(exports) { var Foo = function(num) { this.num = num }; var addTwo = function() {...

When I'm trying to do object-oriented pure JS with private methods, I frequently do the following (function(exports) { var Foo = function(num) { this.num = num }; var addTwo = function() {...

  1. private object functions
  2. javascript private functions in object