How to load MVC Partial View and keep Angular JS working

后端 未结 2 1082
别那么骄傲
别那么骄傲 2021-01-21 05:29

How should I load mvc partial views and keep Angular JS working. Angular JS is working fine after I render the layout, but if I load partial views in the layout, Angular JS is n

2条回答
  •  情深已故
    2021-01-21 05:45

    Instead of inject your HTML manually. Be it through angular.element.html or $().html. Try using one of the following, angular approved, options:

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

    Because these are AngularJS friendly methods, Angular will actually parse the HTML and bind any values within the newly loaded HTML.

提交回复
热议问题