Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between angular.module and window.angular.module?

I'm code reviewing the following:

(function () {
    'use strict';

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

I've been using

angular
    .module('myModule')
    //etc

rather than starting with window.angular.

Since I presume angular is scoped against the window, is there any real, practical difference between these two syntaxes?

like image 936
StuperUser Avatar asked Feb 18 '26 17:02

StuperUser


2 Answers

not at all. in browsers window is the global object,

and as written here - 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"
    
like image 110
MoLow Avatar answered Feb 21 '26 06:02

MoLow


Any variable defined globally is attached to the window. So no there is no real practical difference.

like image 42
kemicofa ghost Avatar answered Feb 21 '26 07:02

kemicofa ghost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!