0

I have gone through this article

Here is my code

@Component({
  moduleId: __moduleName,
  selector: 'header',
  template: require('./header.component.html'),
  styleUrls: ['/header.component.css']
})

The line

moduleId: __moduleName,

is giving error: Cannot find name '__moduleName'.

tsconfig.json file:

{
"compilerOptions": {
  "sourceMap": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "removeComments": false,
  "noImplicitAny": false
},
"compileOnSave": false,
"filesGlob": [
  "src/**/*.ts",
  "src/**/*.tsx",
  "!typings/**",
  "!node_modules/**"
]
}

I am using SystemJS. Please Help!

amansoni211
  • 889
  • 2
  • 13
  • 30

1 Answers1

0

You can use one of these options:

CommonJS

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs", // this line
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

component:

@Component({
  moduleId: module.id,
  selector: 'header',
  templateUrl: 'header.component.html',
  styleUrls: ['header.component.css']
})

SystemJS

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system", // this line
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

component:

declare var __moduleName: any;

@Component({
  moduleId: __moduleName,
  selector: 'header',
  templateUrl: 'header.component.html',
  styleUrls: ['header.component.css']
})

There are also special loaders to load your html without specifying module option (https://github.com/angular/angular/issues/6053#issuecomment-222341010)

Webpack users can use require('./some-template.html') - see https://angular.io/docs/ts/latest/guide/webpack.html for an example of how to use this.

SystemJS has the ability to use loaders for text in a similar fashion - https://github.com/systemjs/plugin-text

See also

Community
  • 1
  • 1
yurzui
  • 205,937
  • 32
  • 433
  • 399