Search code examples
javascriptangularjstextangular

How to ignore images in the textAngular editor


Facing issue with the textAngular editor when user copy and paste text. (clip board contains text and image)

You can find library from here https://github.com/fraywing/textAngular.


Solution

  • Checkout this fiddle. It uses ta-past directive of textAngular and replaces all image elements by using regex .replace(/<img[^>]*>/g,""); on your input string.

    View

    <div ng-app="test">
        <div ng-controller="testController">
            <div text-angular 
                 name="testEditor" 
                 ng-model="htmlContent" 
                 ta-paste="stripFormat($html)"></div>
        </div>
    </div>
    

    AngularJS Application

    angular.module('test', ['textAngular'])
      .controller('testController', function($scope, $timeout, textAngularManager, $filter) {
    
      $scope.htmlContent = '<p>Hello There!</p>';
    
      $scope.stripFormat = function ($html) {
        return $html.replace(/<img[^>]*>/g,"");
      };
    });