angular - 为什么我在刚启动的 Angular2 应用程序中会收到此错误?

标签 angular

我刚开始编写一个全新的 angular2 应用程序,我从中克隆了它 https://github.com/angular/quickstart

为什么会出现此错误?

app/app.component.ts(8,3): error TS2345: Argument of type '{ moduleId: string; selector: string; templateUrl: string; directives: string[]; }' is not assignable to parameter of type 'Component'. Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.

app.component.ts

import { Component } from '@angular/core';
import { NavbarComponent } from './components/navbar/navbar.component';

@Component({
  moduleId: module.id,
  selector: 'my-app',
  templateUrl: 'app.component.html',
  directives: [NavbarComponent]
})
export class AppComponent  {  }

navbar-component.ts

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

@Component({
  moduleId: module.id,
  selector: 'navbar',
  templateUrl: `navbar.component.html`,
})
export class NavbarComponent  {  }

最佳答案

app.component.ts

中删除以下行
directives: [NavbarComponent]

并将其添加到app.module.ts

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent, NavbarComponent ], << add here
  bootstrap:    [ AppComponent ]
})

从 2.0.0-rc.6 开始不再提供指令

关于angular - 为什么我在刚启动的 Angular2 应用程序中会收到此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41326611/

相关文章:

typescript - Angular 2 : Catching 401 error for token refresh

angular - 设置 Formgroup 有效或无效 angular 7

angular - 覆盖组件,比如服务?

javascript - 将对象传递给函数内部的函数 - 作用域问题

angular - ag-param() 在 ag-register-params 之前调用

angular - 类型 'distinctUntilChanged' 上不存在属性 'Observable<Event>'

testing - 在生产模式下隐藏 angular2 组件的最佳解决方案?

javascript - Angular 2 缓慢的初始加载

angular - Ionic 2 日历事件源属性绑定(bind)不更新 View

Angular aot 构建 : dynamic forRoot parameter results in undefined