简体   繁体   English

Angular 2 - MEAN MongoDB NodeJS

[英]Angular 2 - MEAN MongoDB NodeJS

I'm using this GitHub example ( https://github.com/bradtraversy/mean_mytasklist ) and it works fine so far. 我正在使用这个GitHub示例( https://github.com/bradtraversy/mean_mytasklist ),它到目前为止工作正常。 I see the tasks of my MongoDB, can add, delete tasks. 我看到我的MongoDB的任务,可以添加,删除任务。

Then I was trying to add a new component "header" 然后我试图添加一个新组件“标题”

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'headers',
  templateUrl: 'header.component.html'
})
export class HeaderComponent {

}

I added this component in my app.modules.ts 我在app.modules.ts中添加了这个组件

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { TasksComponent } from './components/tasks/tasks.component';
import { HeaderComponent } from './components/header/header.component';

@NgModule({
  imports: [BrowserModule, HttpModule, FormsModule],
  declarations: [AppComponent, TasksComponent, HeaderComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }

In my app.component.html I am using this selector. 在我的app.component.html中,我正在使用此选择器。

<div class="container">
    <headers></headers>
    <h1>MyTaskList</h1>
    <hr>
    <tasks></tasks>
</div>

After refreshing my browser I'll get this error message: 刷新浏览器后,我会收到以下错误消息:

zone.js:420 Unhandled Promise rejection: Template parse errors: 'headers' is not a known element: 1. If 'headers' is an Angular component, then verify that it is part of this module. zone.js:420未处理的Promise拒绝:模板解析错误:'headers'不是已知元素:1。如果'headers'是Angular组件,则验证它是否是此模块的一部分。 2. If 'headers' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. 2.如果'headers'是Web组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的'@NgModule.schemas'以禁止显示此消息。 (" [ERROR ->] (“[错误 - >]

<headers></headers>
<h1>MyTaskList</h1>
<hr>

Any ideas? 有任何想法吗? Many thanks!!! 非常感谢!!!

"): AppComponent@1:4 ; Zone: ; Task: Promise.then ; “):AppComponent @ 1:4;区域:;任务:Promise.then;

Which version of Angular 2 you are using & You are not using webpack for build ? 您正在使用哪个版本的Angular 2并且您没有使用webpack进行构建?

The solution is mentioned in the error console itself. 错误控制台本身提到了解决方案。 You need to add 你需要添加

schemas: [CUSTOM_ELEMENTS_SCHEMA ] 

So your app.module.ts should look something like this, 所以你的app.module.ts应该是这样的,

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  imports: [BrowserModule, HttpModule, FormsModule],
  declarations: [AppComponent, TasksComponent, HeaderComponent],
  bootstrap: [AppComponent],
   schemas: [CUSTOM_ELEMENTS_SCHEMA ] 
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM