How to load partial MVC view and keep Angular JS working

How do I load mvc partial views and keep Angular JS working. Angular JS works fine after rendering the layout, but if I load the partial views in the layout Angular JS no longer works in the partial ones. I think Angular doesn't compile ng directives after I insert HTML into DOM.

+3


source to share


2 answers


Instead of entering your HTML manually. Go through angular.element.html or $ (). Html. Try one of the following: angular approved, parameters:

  • A routing engine like ngRoute or ui-router. The mechanism can include a template that is generated by the backend.
  • ngInclude . This way you can directly include HTML templates.
  • Write a custom directive that injects your HTML.


Since these are AngularJS friendly methods, angular will actually parse the HTML and bind any values ​​inside the newly loaded HTML.

+2


source


From the answer here

I think you might need to compile HTML string or DOM to template.

For more information, please refer to:

$ compile

https://docs.angularjs.org/api/ng/service/ $ compile



There are some topics that might help you:

AngularJS - Dynamically Generating Directive Defining Elements

AngularJS - Dynamically Generating Directive Defining Elements

Bind Angularjs to newly created html element dynamically

Dynamically bind to newly created html element

0


source







All Articles