【问题标题】:Template in my custom component not working in app.component.html我的自定义组件中的模板在 app.component.html 中不起作用
【发布时间】:2017-12-21 09:01:03
【问题描述】:

【问题讨论】:

  • 请在此处添加您的代码。
  • 从'@angular/core'导入{组件}; @Component( { selector: 'course', template: '

    Course

    ' } ) mycustom class export class CoursesComponent { }
  • 从 '@angular/platform-b​​rowser' 导入 { BrowserModule };从'@angular/core'导入{ NgModule };从'./app.component'导入{AppComponent};从'./Courses.Component'导入{ CoursesComponent }; @NgModule({ 声明:[ AppComponent, CoursesComponent ],导入:[ BrowserModule ],提供者:[],引导程序:[AppComponent] }) 导出类 AppModule { }
  • appcomponent.html 课程>

标签: angular


【解决方案1】:

您可能应该收到如下警告:

WARNING in ./src/app/Courses.Component.ts
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem 
with other case-semantic.
Use equal casing.

因为这里的组件中有大写字母 C:

import { CoursesComponent } from './Courses.Component';

请尝试:

import { CoursesComponent } from './Courses.component';

【讨论】:

    【解决方案2】:

    我认为这足以让组件正常工作。你能在浏览器日志中显示你的错误吗?在 Angular2+ 中,您应该使用 ng generate component componentname 创建组件,请参阅 here。

    【讨论】:

      猜你喜欢
      • 2020-04-09
      • 1970-01-01
      • 2014-06-27
      • 2011-09-30
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多