Angular 2 RC6 - “侧边栏"不是已知元素 [英] Angular 2 RC6 - "sidebar" is not a known element

查看:27
本文介绍了Angular 2 RC6 - “侧边栏"不是已知元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新到 RC6,遇到以下错误:

<块引用>

zone.min.js:1 未处理的 Promise 拒绝:模板解析错误:侧边栏"不是已知元素:1. 如果侧边栏"是一个 Angular 组件,则验证它是否是该模块的一部分.2. 如果'sidebar' 是一个Web 组件,则将CUSTOM_ELEMENTS_SCHEMA"添加到该组件的'@NgModule.schema' 以抑制此消息.("

sidebar 不是组件.只是我在其中一个模板中使用的 html 标签.它们看起来像这样:

<预><代码>...<sidebar class="main-nav">...</侧边栏>...

我尝试使用 CUSTOM_ELEMENTS_SCHEMA 更新我的 NgModule AppModule,如下所示:

@NgModule({声明:[...],提供者:[...],进口:[BrowserModule,路由,HttpModule,FormsModule,TranslateModule.forRoot()],引导程序:[AppComponent],架构:[ CUSTOM_ELEMENTS_SCHEMA ]})导出类 AppModule { }

但这似乎没有任何作用.

有人有想法或提示吗?

解决方案

感谢 Pankaj Parkar 的评论.

sidebar 似乎还没有被接受.我不得不实施一个解决方法.

sidebar.directive.ts

import { Directive } from '@angular/core';/*** 允许 html 标签侧边栏"的伪指令*/@Directive({ 选择器:'侧边栏'})导出类 SidebarDirective {}

将其包含在 app.module.ts

@NgModule({声明: [..., SidebarDirective],...})导出类 AppModule { }

I just updated to RC6 and have trouble with the following error:

zone.min.js:1 Unhandled Promise rejection: Template parse errors: 'sidebar' is not a known element: 1. If 'sidebar' is an Angular component, then verify that it is part of this module. 2. If 'sidebar' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("

sidebar isn't a component. Just a html-tag i am using in one of my templates. They look like this:

...
<sidebar class="main-nav">
    ...
</sidebar>
...

I tried updating my NgModule AppModule with CUSTOM_ELEMENTS_SCHEMA like this:

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

But that doesn't seem to do anything.

Does anyone haven an idea or a hint?

解决方案

Thanks to Pankaj Parkar for his comment.

sidebar seems not to to be accepted yet. I had to implement a workaround.

sidebar.directive.ts

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

/**
 * dummy directive to allow html-tag "sidebar"
 */
@Directive({ selector: 'sidebar'})
export class SidebarDirective {}

Include it in app.module.ts

@NgModule({
    declarations: [..., SidebarDirective],
...
})
export class AppModule { }

这篇关于Angular 2 RC6 - “侧边栏"不是已知元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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