0

I'm getting a html with angular content from a service, the content is something like that

<div>{{ @event.dateBegin | stringToDate }}</div>

the service is something like

$scope.setContext = function() {
   $http.get(service).success(function(response) {
          $scope.content = response;
    });                   

the content div is

<div class="span9" ng-bind-html-unsafe="content"></div>

and for result I got the correct html formmed div, but the part {{ }} dosen't work,I agree angular-sanitize but dosen't work too

Javier Gutierrez
  • 549
  • 5
  • 16

1 Answers1

1

You can use the $interpolate service. Example in the docs:

var $interpolate = ...; // injected
var exp = $interpolate('Hello {{name}}!');
expect(exp({name:'Angular'}).toEqual('Hello Angular!');

So, in your specific example, inside your success callback:

var exp = $interpolate(response);
$scope.content = exp(event);

As a recommendation, I would just pass back the data, not the HTML, if you can help it and keep all of the templates in your angular application.

Xesued
  • 4,147
  • 2
  • 25
  • 18
  • I trying use a component like this @event.name , but dosen't work – Javier Gutierrez Mar 27 '13 at 22:44
  • Well, first off you need your variable `event.name` in the {{}}s so that the value can be injected in the template. Second, @event is not a valid java script variable: see [here](http://stackoverflow.com/questions/1661197/valid-characters-for-javascript-variable-names) – Xesued Mar 28 '13 at 02:44
  • @event is a variable in playframwork, I'm refer to the tooltip ui component in angular bootstratp – Javier Gutierrez Mar 28 '13 at 15:09