2

Why is it necessary to use moduleId:module.id at the time of using templateUrl in Angular 2 Component .

import { Component } from '@angular/core';

@Component({
  moduleId:module.id,
  selector: 'my-app',
  templateUrl:`app.component.html`,
})

export class AppComponent  { name = 'Angular 2 website'; }
Maxim Kuzmin
  • 2,574
  • 19
  • 24
dpk45
  • 107
  • 2
  • 12
  • ` moduleId:module.id` for resolving relative path – anshuVersatile Feb 17 '17 at 12:19
  • 4
    Possible duplicate of [Angular2 - What is the meanings of module.id in component?](http://stackoverflow.com/questions/37178192/angular2-what-is-the-meanings-of-module-id-in-component) – jonrsharpe Feb 17 '17 at 13:32

1 Answers1

5

relative assets for components, like templateUrl and styleUrls in the @Component decorator.

moduleId is used to resolve relative paths for your stylesheets and templates as it says in the documentation.

Without Module ID

@Component({
  selector: 'my-component',
  templateUrl: 'app/components/my.component.html',
  styleUrls:  ['app/components/my.component.css'] 
})

With Module ID

@Component({
  moduleId: module.id,
  selector: 'my-component',
  templateUrl: 'my.component.html', 
  styleUrls:  ['my.component.css'] 
})
anshuVersatile
  • 2,030
  • 1
  • 11
  • 18