angular使directive让div contenteditable & ng-model生效

.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);
      });
    }
  };
})


你可能感兴趣的:(angular使directive让div contenteditable & ng-model生效)