Git Product home page Git Product logo

angular2-moduleid-loader's Introduction

angular2-moduleid-loader

What is moduleId

ModuleId is a metadata property you can set when defining a component (in the @Component section). When using CommonJS, it allows you to use relative path inside the templateUrl and styleUrls metadata properties. For example, if your .ts files are in the same folder as your .html files, instead of having:

@Component({
  selector: 'my-component',
  templateUrl: 'app/my/my.component.ts'
})
export class MyComponent { }

You can have:

@Component({
  moduleId: module.id,
  selector: 'my-component',
  templateUrl: 'my.component.ts'
})
export class MyComponent { }

More information here: https://angular.io/docs/ts/latest/cookbook/component-relative-paths.html

If you try to use moduleId: module.id when using Webpack, you get this error when loading the bundled website:

Error: moduleId should be a string in "MyComponent". See https://goo.gl/wIDDiL for more information. If you're using Webpack you should inline the template and the styles, see https://goo.gl/X2J8zc.

With this loader, you can keep the moduleId: module.id and your code will work whether you are using Webpack or not.

This is handy if you are using something that does its own bundling (for example using karma-typescript for testing) and needs the moduleId to handle your relative paths.

angular2-moduleid-loader's People

Contributors

kevindqc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.