Search code examples
angularjsmodulerequirements

How to use the REQUIRES parameter in a MODULE creation - angularjs


The syntax for usage of a module is:

angular.module(name, [requires], [configFn]);

The Type for the [requires] parameter is:

!Array.<string>=

I have no idea what that means. What does the exclamation point signify, that it's NOT an Array? Why is there an equal sign at the end? What is the period for?

Looking at another Stackoverflow question, the [requires] parameter is used to list other modules that this module uses. So, is this sort of like an Include statement, that puts another module inside of this module?


Solution

  • It is the Google Closure Compiler Type Expressions syntax.

    • Array.<string> means an array of strings
    • ! at the beginning means it cannot be null
    • = at the end means it is optional

    Combine them together and we got: !Array.<string>= means it can be

    • an array of strings
    • an empty array
    • undefined (optional)

    But it cannot be null