can.import

  • function
 

Imports a module with the underlying module loader.

util.import(moduleName)

Imports a module with the underlying module loader.

Parameters

  1. moduleName {String}

    The module name to load. Example: components/my-component.

Returns

{Promise}

A promise that resolves if the module was successfully loaded and is rejected if the module can not be successfully loaded.

Use

can.import is used internally by can.autorender when it finds <can-import> tags to import those modules before rendering the template.

In the following example, can.import will import "components/my-component" prior to the template being rendered.

 <script type='text/stache' can-autorender>
    <can-import from="components/my-component">
    <my-component>
      {{message}}
    </my-compoennt>
  </script>

Module Loaders

can.import looks first for a System loader, followed by require.amd, followed by steal followed by a CommonJS require.