加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

将应用程序升级到Angular2 RC6

发布时间:2020-12-17 17:50:56 所属栏目:安全 来源:网络整理
导读:我刚刚将我的应用程序从angular2 RC5更新为RC6,我仍然在选择器中出错 这是控制台 Unhandled Promise rejection: Template parse errors: 'time-filter' is not a known element: 1. If 'time-filter' is an Angular component,then verify that it is part o
我刚刚将我的应用程序从angular2 RC5更新为RC6,我仍然在选择器中出错

这是控制台

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

这是我的组件代码:

@Component({
    selector: 'time-filter',templateUrl: '../app/shared/time-filter/time-filter.html',providers: [TimeService]
})

export class TimeFilter implements OnInit
{..}

这就是我所说的

import { Component,NgModule,SchemaMetadata } from '@angular/core';
import {TimeFilter} from '../shared/time-filter/time-filter.component';

@Component({
    template: `<div>
               <time-filter></time-filter>
        </div>
`

})
@NgModule({
        declarations: [TimeFilter]
})

解决方法

在@Component中,添加选择器并在@NgModule的声明中定义相同的组件.

像这样创建AppComponent-

import { Component } from '@angular/core';
import { TimeFilter } from '../shared/time-filter/time-filter.component';

@Component({
selector: 'my-app',template: `<div>
           <time-filter></time-filter>
        </div>
`
})

然后在AppModule中声明这两个组件,如下所示 –

@NgModule({
    imports: [BrowserModule],declarations: [AppComponent,TimeFilter]
    bootstrap: [AppComponent]
})
export class AppModule { }

另外,不要在单个文件中混合使用@component和@ngmodule.每个文件定义一件事(例如服务或组件).参见angular2 style guide

看看这是否有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读