【问题标题】:angular2 cannot find my component referenceangular2 找不到我的组件参考
【发布时间】:2016-08-28 04:35:54
【问题描述】:

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

虽然文件已经到位。

我该如何解决这个问题?

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

【问题讨论】:

  • 您有文件push.component.ts,但浏览器正在寻找push.component
  • 你是如何加载你的模块的?
  • @ReidHorton 那么我应该如何更改我的代码?
  • @ErnestoCampohermoso 使用 intellij。添加了我的 module.ts
  • @ReidHorton 是对的,您应该检查您的映射在客户端中的完成方式,这很可能是您的 system.js 配置中的默认扩展问题

标签: javascript html intellij-idea angular


【解决方案1】:

如果您使用的是@NgModules,则不需要在AppComponent 中导入推送组件和directives 属性。

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

【讨论】:

  • 这不是问题,因为导航器清楚地说明了这一点。而且你的回答不好,因为他的 Module 组件也会有同样的问题。
  • PushComponent 可能没有导出类。附言在 Angular 的最终版本中,我们必须删除指令属性。
猜你喜欢
  • 2019-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多