Angular2 CUSTOM_ELEMENTS_SCHEMA Doesn't Work

让人想犯罪 __ 提交于 2019-12-04 04:51:57

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

imports: [RowComponent]

Edit:

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

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

If you take a look at changelog https://github.com/angular/angular/blob/master/CHANGELOG.md#200-rc5-2016-08-09

By default, Angular will error during parsing on unknown properties, even if they are on elements with a - in their name (aka custom elements). If you application is using custom elements, fill the new parameter @NgModule.schemas with the value [CUSTOM_ELEMENTS_SCHEMA].

then you can understand that you need to have tag with - delimiter

if (tagName.indexOf('-') > -1) {
      if (tagName === 'ng-container' || tagName === 'ng-content') {
        return false;
      }

      if (schemaMetas.some((schema) => schema.name === CUSTOM_ELEMENTS_SCHEMA.name)) {
        // Can't tell now as we don't know which properties a custom element will get
        // once it is instantiated
        return true;
      }
}

https://github.com/angular/angular/blob/2.4.8/modules/%40angular/compiler/src/schema/dom_element_schema_registry.ts#L290

so something like my-row should work

The following are your mistakes

  1. You have imported only AppComponent but it does not have any element with <row> as its template.
  2. CUSTOM_ELEMENTS_SCHEMA need not be used during application development as it is used to hide errors that are caused occurs when templates are being parsed (as said in your error description).
  3. <app-root> is the selector for your AppComponent, but you have used <row> in your html of the AppComponent.

Based on your requirement, I can suggest with various fixes. Comment with your desired outcome and I shall update answer based on them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!