Update application to Angular2 RC6

I just upgraded my application from angular2 RC5 to RC6 and I still got errors in the selectors

this is the 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 what 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]
})
+4
source share
2 answers

In @Componentadd selectorand define the same component in the ads @NgModule.

Create an AppComponent as follows:

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 the AppModule as follows:

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

Also, do not mix @Componentand @NgModulein a single file. Define one thing (for example, a service or component) for each file. Refer to angular2 style guide

See if that helps.

+5
source
+3

Source: https://habr.com/ru/post/1653594/


All Articles