本文介绍了Angular2 CUSTOM_ELEMENTS_SCHEMA不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用ng2 cli安装了Bearbones ng2应用程序.在我的AppModule中添加了schema: [ CUSTOM_ELEMENTS_SCHEMA ],在我的AppComponent模板中添加了<row></row>.但是我得到了-

I have just installed a bearbones ng2 app using the ng2 cli. In my AppModule I added schema: [ CUSTOM_ELEMENTS_SCHEMA ], and in my AppComponent template I have <row></row>. But I'm getting-

AppModule-

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-

AppComponent-

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

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

AppComponentTemplate-

AppComponentTemplate-

<row></row>

就是这么简单.到底发生了什么事?

It's really that simple. What the heck is going on?

以下所有答案都令人满意,可以深入了解问题. @yurzui我特别喜欢您提供资料来源的答案.希望我能给大家所有可以接受的答案!但是我会选择@camaron作为第一个,并直接解决我的问题.如果您通过Google找到此问题,请给@ yurzui,@ camaron和@Aravind +1以帮助解决此问题!

All of the answers below are satisfactory and provide insight into the problem. @yurzui I especially like your answer for providing the source. I wish I could give you all the accepted answer! But I will choose @camaron for being the first and giving the direct solution to my problem. If you find this question via google please give @yurzui, @camaron, and @Aravind a +1 for helping with this issue!

推荐答案

您需要添加要由AppModule

imports: [RowComponent]

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

Use NO_ERRORS_SCHEMA, this is because angular is trying to find an component that doesn't exists.

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

CUSTOM_ELEMENTS_SCHEMA is for components with a - in the selector name.

这篇关于Angular2 CUSTOM_ELEMENTS_SCHEMA不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:55
查看更多