I have my own NgModule published and installed via npm. Currently the template of the component in the imported module has a inline template. The template got huge (200+ LOC) over time and it would be nice to use the templateUrl instead of inline template in the component.
So instead of this:
template: `<h1>My template</h1>`,
I want to use this:
templateUrl: './my-template.html'
All the solutions explained in the folowing post don't work if the module/component is imported via node_modules. https://blog.thoughtram.io/angular/2016/06/08/component-relative-paths-in-angular-2.html
I know there are some solutions with gulp packages, that resolve the path and put the template as inline string, but is there any other solution to this?
Edit (add more code examples):
import {Component} from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: './my-template.html'
})
export class MyComponent {
constructor() {
}
}
The template is in the same directory as the ts file. It works if I move the directory from node_modules/my-package/my-component and put it anywhere in src/app/.
module: module.id
has to be set in your @Component decorator, otherwise Angular 2 will be looking for your files at the root levelmodule: module.id
the application won't start with the errorError: moduleId should be a string in MyModule
. And yes you are right, Angular is looking at the root level for the files