AngularJS and Jquery: angular dosen't bind on jquery navigation

淺唱寂寞╮ 提交于 2019-12-12 06:47:03

问题


Jquery is ignoring all Angular ng binds(ng-app,ng-controller,ng-bind..) on page change.They are working in index but when I navigate to other pages ng-s just aren't working.Is there a way to "rebind" angular when page dynamically changes?

in first html:

<section data-role="page" ng-app="aki" ng-controller="akicontroller">

<a href="sec.html"></a>

</section>

in second html ng-app and ng-controller are ignored:

<section data-role="page" ng-app="aki" ng-controller="akicontroller">

</section>

Pages are loaded via jquery in dom.

Thank you in advance.


回答1:


ng-app is used for designating the root of the app and should be placed in root elements of the page (html/body). If you do actually need >2 apps running in one html document then you must bootstrap them. Refer to the Angular documentation for ng-app: https://docs.angularjs.org/api/ng/directive/ngApp




回答2:


If you are going to use jquery with angular, you should convert any plugin into a directive. The video below explains alot on how it is done.

https://www.youtube.com/watch?v=9Bu73oQQSio

This will ensure that your bindings update.



来源:https://stackoverflow.com/questions/23725376/angularjs-and-jquery-angular-dosent-bind-on-jquery-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!