AngularJS data bind in ng-bind-html?

后端 未结 3 514
走了就别回头了
走了就别回头了 2020-11-29 07:57

Is it possible to bind data of scope variable to a html that is about to bind as ng-bind-html?

ie, I have a

html =\"
{{caption}}
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 08:21

    You should use $interpolate not $compile.
    Write controller like this:

    angular.module('app', ['ngSanitize'])
      .controller('MyCtrl', ['$scope', '$interpolate', function($scope, $interpolate){
       $scope.caption = 'My Caption';
       $scope.html = $interpolate('
    {{caption}}
    ')($scope); });

    Then write HTML like this:

提交回复
热议问题