简体   繁体   English

将应用程序升级到Angular2 RC6

[英]upgrade application to Angular2 RC6

i have just updated my application from angular2 RC5 to RC6 and I still got errors at the selectors 我刚刚将我的应用程序从angular2 RC5更新为RC6,我仍然在选择器中出错

this is console 这是控制台

> 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>

and this is my component code : 这是我的组件代码:

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

export class TimeFilter implements OnInit
{..}

and that's how i call it 这就是我所说的

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]
})

In @Component , add selector and define same component in declarations of @NgModule . @Component ,添加selector并在@NgModule声明中定义相同的组件。

Create AppComponent like this- 像这样创建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>
`
})

and then declare both components in AppModule like this- 然后在AppModule中声明这两个组件,如下所示 -

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

Also, do not mix @component and @ngmodule in single file. 另外,不要在单个文件中混合使用@component@ngmodule Do define one thing (eg service or component) per file. 为每个文件定义一件事(例如服务或组件)。 Refer angular2 style guide 请参阅angular2 样式指南

See if this helps. 看看这是否有帮助。

Also, be aware that in RC6 angular deprecated the directives and pipes from @component (so you should move those to the upper module). 另外,请注意在RC6中,对@component中的指令和管道不推荐使用(所以你应该将它们移到上层模块)。 you can read more about it here https://github.com/angular/angular/commit/4a740f2 你可以在这里阅读更多关于它的信息https://github.com/angular/angular/commit/4a740f2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM