简体   繁体   English

RequireJS与Angularjs在同一页面上加载控制器

[英]RequireJS with Angularjs for loading controllers on the same page

I have done a lot of research for requireJS AMD in AngularJS and found out that 我在AngularJS中对requireJS AMD进行了很多研究,发现

the JS files are being called by triggers either by changing url or clicking a button 触发器通过更改URL或单击按钮来调用JS文件

I have the home page which is divided into 5 sections with each one having its html and controller file. 我的主页分为5个部分,每个部分都有其html和controller文件。

The motive is to call only the first section on page load with its controller and html file. 目的是仅调用页面加载的第一部分及其控制器和html文件。 And load the rest files one by one as we scroll to the bottom. 滚动到底部,然后逐一加载其余文件。

Is there any way to do that? 有什么办法吗? Or I will have to change the URL whenever I go to the next sections? 还是每到下一节都要更改URL?

just simply use javascript and require(['your_controller']); 只需简单地使用javascript和require(['your_controller']);

like: 喜欢:

document.addEventListener("scroll", function(){
    if(document.body.scrollTop == 500){
        require(['your_controller']);
    }
});

This will add your_controller.js to your page when you scroll down 500px from the top of the page. 当您从页面顶部向下滚动500px时,这会将your_controller.js添加到页面中。 But still it may not be work in the way you expecting. 但是仍然可能无法按您期望的方式工作。 I have never done such thing to load a controller, but according to your question. 我从来没有做过这样的事情来加载控制器,而是根据您的问题。 This will help you load the script file of your controller. 这将帮助您加载控制器的脚本文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM