Angular 角度2组件.html路径
我尝试在组件中使用html的相对路径,同时在dist文件夹中映射我的js文件。。我的组件代码是 app/app.component.tsAngular 角度2组件.html路径,angular,angular2-template,angular2-components,Angular,Angular2 Template,Angular2 Components,我尝试在组件中使用html的相对路径,同时在dist文件夹中映射我的js文件。。我的组件代码是 app/app.component.ts import { Component } from '@angular/core'; @Component({ moduleId: module.id, selector: 'my-app', templateUrl: 'app.component.html' }) export class AppComponent { } html文件位于同一
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html'
})
export class AppComponent { }
html文件位于同一目录中,即
app/app.component.html
<h1> Wolaa </h1>
我的tsconfig.json是
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "dist"
}
}
以下是文档中有关模板相对路径的一些详细信息,可能会有所帮助: 尝试在相对路径前放置“/”,如:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent { }
这是迄今为止我能找到的最佳解决方案:
moduleId:module.id.replace(“/dist/”,“/src/”)代码>在我的例子中,src
是app
。
取自。这不是解决方案。问题仍然存在,因为dist
目录不包含hrml和css文件。它们也需要复制到dist
。确实如此:(可能移动到webpack会避免这种情况。我会在不久的将来尝试。但是,它很有效,而且还是一行:)
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent { }