gpt4 book ai didi

angularjs - 不同模块中的 angular.js 指令

转载 作者:行者123 更新时间:2023-12-02 19:04:27 30 4
gpt4 key购买 nike

我很困惑。如果我每个页面只能使用 ng-app 一次,我如何使用位于不同模块、不同 .js 文件中的指令。看:

<script src='mainModule.js'/>
<script src='secondModule.js'/>
<body ng-app='mainModule'>
<my-thingy/>
<div>
<other-thingy/>
</div>
</body>

mainModule.js:
angular.module("mainModule",[]).directive("myThingy",function(){ ... })

secondModule.js:
angular.module("secondModule",[]).directive("otherThingy",function(){ ... })

那么,我现在如何指向页面上的第二个模块,而不从 mainModule.js 引用它

最佳答案

@Agzam,只需创建第三个顶级应用程序模块,该模块将依赖于包含指令的子模块:

<script src='mainModule.js'/>
<script src='secondModule.js'/>
<script>
angular.module('app', ['mainModule', 'secondModule'])
</script>
<body ng-app='app'>
<my-thingy/>
<div>
<other-thingy/>
</div>
</body>

关于angularjs - 不同模块中的 angular.js 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15641730/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com