Angular 角度不是已知元素-模板分析错误
我刚开始使用angular,但我在angular拾取新组件时遇到了问题 我已经重建并重新启动了服务器,但什么都没有 应用程序模块文件如下所示Angular 角度不是已知元素-模板分析错误,angular,angular-components,Angular,Angular Components,我刚开始使用angular,但我在angular拾取新组件时遇到了问题 我已经重建并重新启动了服务器,但什么都没有 应用程序模块文件如下所示 import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppComponent } from "
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from "./app.component";
import { MessageComponent } from "./messages/message.component";
@NgModule({
declarations: [
AppComponent,
MessageComponent
],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent]
})
export class AppModule {
}
import { Component } from '@angular/core';
@Component({
selector: 'app-message',
templateUrl: './message.component.html'
})
export class MessageComponent {
}
<article class="panel panel-default">
<div class="panel-body">
{{message.content}}
</div>
<footer class="panel-footer">
<div class="author">
{{message.author}}
</div>
<div class="config">
<a href="">Edit</a>
<a href="">Delete</a>
</div>
</footer>
</article>
应用程序组件html很好,也很简单
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<app-message></app-message>
</div>
</div>
</div>
message.component.html如下所示
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from "./app.component";
import { MessageComponent } from "./messages/message.component";
@NgModule({
declarations: [
AppComponent,
MessageComponent
],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent]
})
export class AppModule {
}
import { Component } from '@angular/core';
@Component({
selector: 'app-message',
templateUrl: './message.component.html'
})
export class MessageComponent {
}
<article class="panel panel-default">
<div class="panel-body">
{{message.content}}
</div>
<footer class="panel-footer">
<div class="author">
{{message.author}}
</div>
<div class="config">
<a href="">Edit</a>
<a href="">Delete</a>
</div>
</footer>
</article>
我得到的模板解析错误,根据图片
尝试将CommonModule作为导入well@SumitAgarwal他为什么要这么做?我们缺少一条信息。您现在共享的代码中没有错误(除了
app message
将失败,因为message
未定义,因此{{message.content}
不起作用。如果您没有输入任何错误,我建议您仔细检查一下。我完全注意到了这一点,通常当我忘记在使用它的模块中声明/导入元素时,我会出现此错误。谢谢您,Pierre,我坚持消息中没有任何错误。模型我错误地键入了“构造函数”.我觉得自己像个傻瓜,但至少现在发现了。我还需要在sublime上加亮显示。我想ittry作为一个模块会有一个角度的包well@SumitAgarwal他为什么要这样做?我们缺少一条信息。你现在共享的代码中没有错误(除了应用程序消息
将失败,因为消息
未定义,因此{{message.content}
不起作用。如果您没有输入任何错误,我建议您仔细检查一下。我完全注意到了这一点,通常当我忘记在使用它的模块中声明/导入元素时,我会出现此错误。谢谢您,Pierre,我坚持消息中没有任何错误。模型我错误地键入了“构造函数”.我觉得自己像个傻瓜,但至少现在找到了。我还需要在“崇高”上加亮显示。我想会有一个棱角分明的包装