Angular2 CUSTOM_ELEMENTS_SCHEMA不起作用

前端之家收集整理的这篇文章主要介绍了Angular2 CUSTOM_ELEMENTS_SCHEMA不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚使用ng2 cli安装了一个bearbones ng2 app.在我的AppModule中,我添加了模式:[CUSTOM_ELEMENTS_SCHEMA],在我的AppComponent模板中,我有< row>< / row>.但我得到 –

Unhandled Promise rejection: Template parse errors:@H_502_3@ ‘row’ is not a known element:@H_502_3@ 1. If ‘row’ is an Angular component,then verify that it is part of this module.@H_502_3@ 2. If ‘row’ is a Web Component then add “CUSTOM_ELEMENTS_SCHEMA” to the ‘@NgModule.schemas’ of this component to suppress this message. (“[ERROR ->]

AppModule-

import { BrowserModule } from '@angular/platform-browser';
import { NgModule,CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';


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

AppComponent-

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

@Component({
  selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})
export class AppComponent {}

AppComponentTemplate-

<row></row>

这真的很简单.到底他妈发生了什么?

编辑:

以下所有答案都令人满意,并提供了对问题的深入了解. @yurzui我特别喜欢你提供源代码的答案.我希望我能给你所有接受的答案!但我会选择@camaron作为第一个并直接解决我的问题.如果你通过谷歌找到这个问题,请给@yurzui,@camaron和@Aravind一个1来帮助解决这个问题!

您需要添加要由AppModule导入的RowComponent

导入:[RowComponent]

编辑:

使用NO_ERRORS_SCHEMA,这是因为angular正在尝试查找不存在的组件.

CUSTOM_ELEMENTS_SCHEMA用于选择器名称中带有 – 的组件.

原文链接:https://www.f2er.com/angularjs/141627.html

猜你在找的Angularjs相关文章