AngularJS 1.2.0 ngBindHtml and trustAsHtml not working with ngModel

前端 未结 1 987
借酒劲吻你
借酒劲吻你 2021-01-21 03:02

I feel like this should be really easy since I had it working perfectly with Angular 1.0.8 using ngBindHtmlUnsafe. I read on the API docs and on StackOverflow that I need to use

1条回答
  •  野性不改
    2021-01-21 04:00

    Is this what you're looking for? http://plnkr.co/edit/IZkzsuKHvbYiyV07CGqp

    // would strongly suggest including sanitize in your scripts and injecting it
    // into your app here to prevent "unsafe as safe" errors
    var myApp = angular.module('myApp', ['ngSanitize']);
    
    myApp.controller('myController', ['$scope', '$sce', function myController($scope, $sce){
      $scope.myHtml = "initial";  //not needed, for testing
    
      $scope.changeText = function() {
        $scope.myHtml = $sce.trustAsHtml($scope.sourceText);
      }
    }]);
    

    Html:

      
        
        
        
        
      
    
      
        

    0 讨论(0)
提交回复
热议问题