角4 templateUrl文件
问题描述:
我采用了棱角分明4.1.3和Rails 5.1角4 templateUrl文件
我想实现的应用程序组件,如果我使用的模板,写我的HTML,一切正常,但我想用templateUrl 。
这是我的组件。
import { Component } from '@angular/core';
@Component({
selector: 'app',
templateUrl: './app.component.html'
})
export class AppComponent {}
这是我的文件结构
├── app
| ├── app.component.html
| └── app.component.ts
| └── app.module.ts
据我所知,在@Component您可以添加的moduleId:module.id,但我认为这不再需要在角4.1.3。
如果我添加它,它告诉我: moduleId should be a string in "AppComponent"
我还认为,如果你不包括的moduleId角从根目录只是抓住,但如果我做了一个绝对路径,它应该工作的权利?
如果你们可以帮忙,那就太棒了。
答
我假设您在rails项目中使用新的webpacker-gem!
还有就是如何在这里使用templateUrl与它的文档中描述:Use HTML templates with Typescript and Angular
答
如果你想保持templateUrl你可以使用angular2模板装载机的WebPack插件:
# add plugins to project
yarn add angular2-template-loader raw-loader
并配置它:
# edit config/webpack/loaders/angular.js with
module.exports = {
test: /.ts$/,
loaders: ['ts-loader', 'angular2-template-loader'],
exclude: [/\.(spec|e2e)\.ts$/]
}
# create a new loader for htmls config/webpack/loaders/html.js
module.exports = {
test: /\.(html)$/,
loader: 'raw-loader',
exclude: /\.async\.(html)$/
}
我不认为这是'moduleId'的问题,但与rails/webpacker默认不支持'templateUrl'。请参阅:https://stackoverflow.com/a/45170420/616292 –