0

I am new in Angular.js and I am playing with it, I am getting an issue when passing the HTML content with $scope object. It returns as a string on browser.

Here what I am doing with my controller

function htmlCtrl($scope, $http,Project) {
  $http.get('/content').success(function(data){
    //  data contains HTML value 
    $scope.projects=data;
  });
}

And in HTML file I am doing this

body     
  div
    div ng-view
    /div
  /div
      !-- /container --
/body

Any help will be appreciated.

1
  • The $sce is what you are looking for, but if you are going to put html snippets, why not use ng-include? Commented Nov 26, 2014 at 8:59

1 Answer 1

5

Use $sce service.

Like this

$scope.project = $sce.trustAsHtml(data);

As for v1.0.3 use ngSanitize, example of using is here

Sign up to request clarification or add additional context in comments.

4 Comments

@abarik, include $sce in service dependency - function htmlCtrl($scope, $http,$sce, Project)
@abarik what version of angular do you use?
I am using this version
@abarik, $sce is available from v1.2. For v1.0.3 which you use try docs.angularjs.org/api/ngSanitize, example of using is here jsfiddle.net/0ajg8m6s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.