1

I'm currently updating parts of my asp.net mvc 5 webapp to angularjs 1.5.

As not everything is angular js, some parts are done with jQuery.

Before angularjs I had <h2>@Model.title</h2> which become <h2>Document XYZ</h2> After moving to angular I'm having a <h2>{{ document.title }}</h2>

I'm trying to get the Document Title out of it and use it somewhere else with jQuery selector $('#documentId').find("h2").text()

Unfortunately, since changing to angular all I get is the expression {{ document.title }}, but not the content which is rendered sucessfully.

Any ideas?

float
  • 1,265
  • 5
  • 22
  • 38
  • put the angularjs variable in a service and use it where you want. Do not mix jquery and angularjs. – thegio Apr 12 '16 at 09:28

1 Answers1

0

You need to call $compile on the HTML string before inserting it into the DOM so that angular gets a chance to perform the binding.

In your fiddle, it would look something like this.

$("#dynamicContent").html(
  $compile(
    "<h2>{{ document.title }}</h2>"
  )(scope)
);

For more reference please check this link click here

Community
  • 1
  • 1