简体   繁体   中英

angular2 cannot find my component reference

I try to load my angular2 app and i get this error

在此处输入图片说明

although the files are in place.

在此处输入图片说明

How can i fix this?

app.component.ts

import {Component} from '@angular/core';
import {PushComponent}  from '../../pages/push/push.component';

@Component({
    selector: 'my-app',
    template: '<h1>My 3rd Angular 2 App</h1> <push-comp></push-comp>',
    directives: [PushComponent]
})
export class AppComponent {
}

and

app.module.js

import {NgModule}      from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {HttpModule}     from '@angular/http';

import {AppComponent}  from './app.component';
import {PushComponent}  from '../../pages/push/push.component';

import {FormsModule} from '@angular/forms';


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

If you are using @NgModules is not neccesary import the push component and the property directives in the AppComponent .

app.component.ts

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

@Component({
    selector: 'my-app',
    template: '<h1>My 3rd Angular 2 App</h1> <push-comp></push-comp>'
})
export class AppComponent {
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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