Module

class Module

A Module is the main control unit for several components, which for example will all access a shared service defined in the module.

A Module can hosts sub-Modules which will be either specified through Modules or with routes

The module is responsible for instantiating the one-and-only router instance

Attributes:

  • bindings ({}):

    A dictionary containing the name and default value of attributes for the class which will also automatically add bound Observables

    The observables will have a _ (underscore) character appended.

    Setting the value of the attribute will trigger the observable and therefore any actions/subscriptions associated with it. Example:

    bindings = {‘myattr’: ‘myvalue’}

    will create:

    • An attribute myattr which defaults to myvalue
    • An observable myattr_
  • services ({}):

    A dictionary containing the name and service class for services defined for this and any child component of it

    services = {‘myservice’: MyService}

  • service_ns (False):

    If False, services will be added as direct attributes of the instance with the name specified in the services declaration.

    If service_ns is:

    • True: the declared services will be reachable under the attribute self._s.myservice

      This is meant to separate the services from the rest of the attributes.

    • A string, the declared services will be reachable under the attribute self.{value of the string}.myservice. I.e.: for a value of services_here, then a service would be reachable as:

      self.services_here.myservice
      
  • modules ([]):

    A single item or an iterable (list/tuple) containing sub-modules which will fall under the control of this module

    Sub-modules won’t actually act as full control units for components, because they won’t, for example, instantiate a router instance

  • components ([]):

    A single item or an iterable (list/tuple) containing components that will be instantiated during start-up. This is usually a single component or even no component at all to let the router auto-output an outlet and decide which components to load with the defined routes

  • routes ([]):

    The list of routes the module will pass to the router. The routes will be extended with children routes coming from sub-modules and load_children definitions

  • router

    Attribute which points to the router instance in charge of the application. Meant for components.

  • router_cls (router.Router)

    Class attribute which holds the class to be instantiated as the one and only router instance

  • selector (None)

    The default behavior of a module controlling an application is that things are plotted in the body of the html document. Where exactly is decided by the rendering engine (i.e.: the browser in most cases).

    If finer control is wished, one can

    • Insert a <module-outlet></module-outlet> tag in the html document and the module will use the tag as the root node for components to be rendered to.
    • Specify a different name in the module definition with for example selector = 'my-module-tag' and later have this as a tag in the html document as in: <my-module-tag></my-module-tag>. Everything will be rendered under this tag.