javascript - What's the dot mean in the name of angular module - Stack Overflow

I am new in this field. When I read some code likeI discover that If I don't put 'myApp.dashb

I am new in this field. When I read some code like I discover that If I don't put 'myApp.dashboard','myApp.value' in angular.module('myApp', ['myApp.dashboard','myApp.value']); It won't work.

If I just write like this:

(function() {
  angular.module('myApp', []);
})();

(function() {
  angular.module('myApp.dashboard', ['myApp.value']);
})();

(function() {
  angular.module('myApp.value', []);
})();

It also doesn't work as well.

Could you tell me what's the dot here mean and why angular.module('myApp.dashboard', ['myApp.value']); doesn't work?

Sorry, this code is really in a mess and I haven't done much about it, just for test.

(function() {
  angular.module('myApp', ['myApp.dashboard','myApp.value']);
})();

(function() {
  angular.module('myApp.dashboard', []);
})();

(function() {
  angular.module('myApp.value', []);
})();

(function() {
  'use strict';
  angular.module('myApp.value').factory('whichToShow', function() {
    alert("running2");
    var logged = true;
    return {
      getVar: function() {
        return logged;
      },
      setVar: function(value) {
        logged = value;
      }

    };
  });
})();

(function() {
  'use strict';
  angular.module('myApp.dashboard').controller('mainControl', mainControl);

  mainControl.$inject = ['whichToShow'];
  alert("running1");

  function mainControl(whichToShow) {
    this.logged = whichToShow.getVar();
    alert("this.logged");
  }
})();

Supplement: I shouldn't ask second question, I made one mistake other place, sorry.

I am new in this field. When I read some code like https://plnkr.co/edit/YeahrG28bT2izX8gMKor?p=preview I discover that If I don't put 'myApp.dashboard','myApp.value' in angular.module('myApp', ['myApp.dashboard','myApp.value']); It won't work.

If I just write like this:

(function() {
  angular.module('myApp', []);
})();

(function() {
  angular.module('myApp.dashboard', ['myApp.value']);
})();

(function() {
  angular.module('myApp.value', []);
})();

It also doesn't work as well.

Could you tell me what's the dot here mean and why angular.module('myApp.dashboard', ['myApp.value']); doesn't work?

Sorry, this code is really in a mess and I haven't done much about it, just for test.

(function() {
  angular.module('myApp', ['myApp.dashboard','myApp.value']);
})();

(function() {
  angular.module('myApp.dashboard', []);
})();

(function() {
  angular.module('myApp.value', []);
})();

(function() {
  'use strict';
  angular.module('myApp.value').factory('whichToShow', function() {
    alert("running2");
    var logged = true;
    return {
      getVar: function() {
        return logged;
      },
      setVar: function(value) {
        logged = value;
      }

    };
  });
})();

(function() {
  'use strict';
  angular.module('myApp.dashboard').controller('mainControl', mainControl);

  mainControl.$inject = ['whichToShow'];
  alert("running1");

  function mainControl(whichToShow) {
    this.logged = whichToShow.getVar();
    alert("this.logged");
  }
})();

Supplement: I shouldn't ask second question, I made one mistake other place, sorry.

Share Improve this question edited Nov 2, 2016 at 23:59 fourth asked Nov 2, 2016 at 23:23 fourthfourth 7492 gold badges7 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

It is actually a coding style that can be followed so as to eliminate the naming collisions.

Use unique naming conventions with separators for sub-modules.

Why?: Unique names help avoid module name collisions. Separators help define modules and their submodule hierarchy. For example app may be your root module while app.dashboard and app.values may be modules that are used as dependencies of app.

Refering to John Papa Angular Style Guide Style Y021

I also suggest you to have a clear understanding about the style guide for every ponent in angular as suggested in the above Github repo by John Papa.

The ['myApp.dashboard','myApp.value'] tells about the dependencies. It means that myApp need to use those dependencies to work.

As for the dot, it's just a good naming convention. You can use without the dot also. The name myApp.dashboard could help to show that the dashboard module is part or submodule of the myApp module. But technically, the dot is not necessary. You can also name it as dashboard only. The dependency is expressed explicitely in the [ ] array, not in the name itself.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744305318a4567701.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信