Angular2 CUSTOM_ELEMENTS_SCHEMA 不起作用 [英] Angular2 CUSTOM_ELEMENTS_SCHEMA Doesn't Work

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

问题描述

我刚刚使用 ng2 cli 安装了一个 Bearbones ng2 应用程序.在我的 AppModule 中,我添加了 schema: [ CUSTOM_ELEMENTS_SCHEMA ],在我的 AppComponent 模板中,我有 ;.但我得到-

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-

未处理的承诺拒绝:模板解析错误:'row' 不是已知元素:1. 如果'row' 是一个Angular 组件,那么验证它是否是这个模块的一部分.2. 如果'row' 是一个Web 组件,则将CUSTOM_ELEMENTS_SCHEMA"添加到该组件的'@NgModule.schemas' 以抑制此消息.("[错误 ->]

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

应用模块-

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 作为第一个并直接解决我的问题.如果您通过谷歌找到这个问题,请给@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!

推荐答案

您需要添加 RowComponent 由您的 AppModule

You need to add the RowComponent to be imported by your AppModule

导入:[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 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆