问题描述
我在Angular 4.1.3和Rails 5.1上使用
I am using Angular 4.1.3 with Rails 5.1
我正在尝试实现应用程序组件,如果我使用模板并编写html,则一切正常,但是我想使用templateUrl.
I am trying to implement the app component and if I use template and write my html, everything works, but I want to use 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版中不再需要此功能.
I understand that in the @Component you can add moduleId: module.id but I thought this is no longer needed in angular 4.1.3.
如果我添加了它,它会告诉我: moduleId应该是"AppComponent"中的字符串
If I do add it, it tells me:moduleId should be a string in "AppComponent"
我还认为,如果不包括从根目录中获取的moduleId角,但是如果我执行绝对路径,它应该工作正常吗?
I also thought that if you do not include the moduleId angular just grabs from root directory, but if I do an absolute path, it should work right?
如果你们能帮助的话,那太好了.
If you guys could help, that would be awesome.
推荐答案
我假设您正在使用新的webpacker-gem 在您的Rails项目中!
I am assuming you're using the new webpacker-gem in your rails project!
在文档中有关于如何使用templateUrl的描述:使用带有Typescript和Angular的HTML模板
There is a description of how to use templateUrl with it here in the documentation: Use HTML templates with Typescript and Angular
这篇关于找不到Angular 4 templateUrl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!