javascript - angular.module 和 window.angular.module 之间有什么区别吗?

标签 javascript angularjs scope

我正在审查以下内容:

(function () {
    'use strict';

    window.angular
          .module('moduleName')
          .directive('DirectiveName', function () {
            return {
                restrict: 'AE',
                templateUrl: '/app/moduleName/list/template.html',
                controller: 'someController',
                controllerAs: 'someCtrl',
            }
        });
}());

我一直在用

angular
    .module('myModule')
    //etc

而不是从 window.angular 开始。

因为我假设 angular 的作用域是针对窗口的,所以这两种语法之间有什么真正的、实际的区别吗?

最佳答案

完全没有。在浏览器窗口中是全局对象,

如这里所写 - https://developer.mozilla.org/en-US/docs/Web/API/Window/window :

In web pages, the window object is also a global object. This means that:

  • global variables of your script are in fact properties of window:

    var global = {data: 0};
    alert(global === window.global); // displays "true"
    
  • you can access built-in properties of the window object without having to type window. prefix:

    setTimeout("alert('Hi!')", 50); // equivalent to using window.setTimeout.
     alert(window === window.window); // displays "true"
    

关于javascript - angular.module 和 window.angular.module 之间有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32113784/

相关文章:

javascript - 将事件处理程序附加到每个 li

Javascript promise 及其参数

maven - 使用 ivy 从 Maven 存储库中解析特定范围

javascript - Ajax 调用 php 脚本从多个复选框表单发送值

javascript - 动态更改facebook评论代码中的url

angularjs - AngularJS中ng-click中的三元表达式

Angularjs 和 Web 服务问题

javascript - 需要从 Angular JS UI 执行 Shell 脚本

c++ - 什么时候分配 block 作用域变量

javascript - 如何更改内容 :url in jquery? 的 css 属性