0

Not sure if anyone has come across this situation before, looking up on google I cant seem to find examples. Bascially I am creating a lenghty html template and i wrap it in a ng-bing-html, it loads my html but it dosent load my interpolation. Let me give you a quick example:

Controller:

$scope.example_text_here = "Hello World!"
$scope.HTML_template = "<p><strong> Example: </strong> {{ example_text_here }}</p>"

HTML:

<div ng-bind-html="HTML_template"></div>

Output

Example: {{ example_text_here }}

What I am expecting:

Example: Hello world!

Anyone know how to accomplish this?

1

3 Answers 3

1

You should use $interpolate module and then injecting current scope or even $compile. See more https://docs.angularjs.org/api/ng/service/$interpolate

$interpolate($scope.HTML_template)($scope)
Sign up to request clarification or add additional context in comments.

2 Comments

Ah this is new to me, very intersting function. Seems to work so far. Thank you so much!.
One small thing tough, the ng-bind-html do not seem to work. Looking this up but would you know what the proper way of doing it with $interpolate?
0

Try This

$scope.HTML_template = "<p><strong> Example: 
 </strong>"+$scope.example_text_here+"</p>";

1 Comment

Thanks but I have an ng-repeat in there also, dont think this will work.
0

I think you'd use $sce service of AngularJS.

Controller:

angular.module('app', [...])

.controller('myCtrl', function($scope, $sce) {
  ...
  $scope.trustAsHtml = function(params) {
    return $sce.trustAsHtml(params);
  };
  ...
  $scope.example_text_here = "Hello World!";
  $scope.HTML_template = "<p><strong> Example: </strong> {{ example_text_here }}</p>";
  ...
});

Markup:

<div ng-bind-html="trustAsHtml(HTML_template)"></div>

Now hope you'd get your expected result. Thanks.

2 Comments

Ill give this a try.
Gives the same result {{ example_text_here }}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.