gpt4 book ai didi

javascript - 使用 angular.module 创建 Controller 有什么好处(如果有的话)?

转载 作者:数据小太阳 更新时间:2023-10-29 04:42:52 25 4
gpt4 key购买 nike

我是 angular.js 的新手,目前正在编写我的第一个项目。

目前我的 Controller 看起来像这样,例如:

function MyCtrl($scope, MyService) {
$scope.foo = MyService.doStuff();
}

他们以这种方式工作得很好(到目前为止),但我浏览了另一个 AngularJS 应用程序的源代码并注意到他们正在使用 angular.module 来创建他们的 Controller 。

如果有的话,我为什么要在自己的应用程序中这样做?

最佳答案

如果您的页面上有多个 Angular 应用程序并且它们具有同名的 Controller ,您需要使用 module.controller 来避免冲突。如果你想避免污染全局命名空间也是如此

关于javascript - 使用 angular.module 创建 Controller 有什么好处(如果有的话)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11388831/

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