Chinmay
Chinmay

Reputation: 4882

Ignore sanitization for a scope variable

I am trying to implement a text editor which can take html input using Angular and TinyMCE. Thing is - if i bind using ngModel, the moment i have mathml tags in that model variable, they get stripped off. Is it possible to ignore sanitization altogether for a scope variable? By sanitization, i mean this - https://docs.angularjs.org/api/ngSanitize/service/$sanitize

This is what i am doing: (for reference)

<script>
        appControllers.controller('appController',['$scope','$sce',
        function($scope, $sce){
            $scope.tinymceOptions = {
                height: '450px',
                statusbar: true,
            };

            $scope.editorText = "<math xmlns:mml='http://www.w3.org/1998/Math/MathML' xmlns:m='http://schemas.openxmlformats.org/officeDocument/2006/math'><mi>H</mi><mi>C</mi><mo>≡</mo><mi>C</mi><mo>-</mo><mtable><mtr><mtd><mtable><mtr><mtd><mi>C</mi><msub><mrow><mi>H</mi></mrow><mrow><mn>3</mn></mrow></msub></mtd></mtr><mtr><mtd><mo>|</mo></mtd></mtr><mtr><mtd><mi>C</mi></mtd></mtr></mtable></mtd></mtr><mtr><mtd><mo>|</mo></mtd></mtr><mtr><mtd><mi>C</mi><msub><mrow><mi>H</mi></mrow><mrow><mn>3</mn></mrow></msub></mtd></mtr></mtable><mo>-</mo><msub><mrow><mi>C</mi><mi>H</mi></mrow><mrow><mn>3</mn></mrow></msub></math>";

            $scope.deliberatelyTrustDangerousSnippet = function(){
                return $sce.trustAsHtml($scope.editorText);
            };
        }]);

    </script>

<textarea ui-tinymce="tinymceOptions" ng-model="editorText"></textarea>
<p>{{deliberatelyTrustDangerousSnippet()}}</p>

Upvotes: 1

Views: 143

Answers (1)

charlietfl
charlietfl

Reputation: 171669

I forget why I did this before but I ran into something similar and this helped me out.

app.config(function ( $sceProvider) {
    $sceProvider.enabled(false);        
});

Beware that this will be applicable throughout the whole app therefore increasing risk when using things like ng-bind-html

Upvotes: 1

Related Questions