1

In my code, I am trying to append a string

var _html = '<div class="env-type-text">${self.environmentType}</div>';

to a div that I can get via a className

var _el = document.getElementsByClassName("domain-wks-env-type-icon")[0];

Now when I append the string to the div by

angular.element(_el).append($compile(_html)($scope));

It shows self.environmentType not it's value.

What am I doing wrong?

7
  • Not sure what is going on here, but you append strings from your controller/directive like this: {{$prefix.environmentType}}. Are you possibly running ng-metadata? That would make things easier for me (and you) Commented Jan 15, 2019 at 8:11
  • {{$prefix.environmentType}} not showing me anything @Joel Commented Jan 15, 2019 at 8:16
  • I think you are trying to mix good ol' javascript with angularjs. You could use the ng-bind-html directive (see docs.angularjs.org/api/ng/directive/ngBindHtml) or even do what you want directly in the template. Commented Jan 15, 2019 at 8:16
  • Possible duplicate of Append HTML with AngularJS Commented Jan 15, 2019 at 8:18
  • 1
    @StrugglingCoder no, i mean, your prefix. Which seems to be self in this example. Also, if all you want to do is to compile html, you can do <p ng-bind-html="self.environmentType"></p> and use the build in functionality for this. Commented Jan 15, 2019 at 8:18

0

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.