0
myApp.directive('qsetAnswer', function(){
  var linker = function(scope,element,attr) {
    console.log(scope.body); // this prints fine.
  };
  return {
    restrict:'A',
    scope: '=info',
    template: '<h5> ' + scope.body + ' </h5>', // this gives error.
    link: linker
  }
});

The above gives:- scope not defined error

Edit:- the problem with template: '<h5>{{body}}</h5>', is that my {{body}} already contains html ie. <p> abc </p> doing it like template: '{{body}}' prints <p> abc </p> like a string.

1 Answer 1

2

Since you're binding HTML to a template, you can use the ng-bind-html directive.

This assumes you're using Angular 1.2+

template: '<h5 ng-html-bind="{{body}}"></h5>',

For Angular <1.2, use

template: '<h5 ng-html-bind-unsafe="{{body}}"></h5>',

If you run into $sce problems with version 1.2+, read the following:

You can tell Angular to trust your HTML, like so:

$scope.ans = $sce.trustAsHtml(' hi <bold> p </bold>');
Sign up to request clarification or add additional context in comments.

1 Comment

@SangramSingh Updated again, with $sce example

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.