angular2找不到我的组件引用

时间:2016-08-27 13:54:37

标签: javascript html intellij-idea angular

我尝试加载我的angular2应用程序,我收到此错误

enter image description here

虽然文件已到位。

enter image description here

我该如何解决这个问题?

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

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

1 个答案:

答案 0 :(得分:0)

如果您使用@NgModules,则无需导入推送组件和directives中的属性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 {
}