私はAngular 2 CLIを使用していて、コンポーネント "MyComponent"をng generate component MyComponent
で作成しました。私の知る限りでは、私は@Component
デコレータの指示キーと値のペアにコンポーネントを追加する必要がありますが、typescriptですコンパイルはと言って、この時点で失敗:新しいコンポーネントをtypescriptでアングル2アプリケーションに追加できません
ERROR in [default] /Users/Philip/Desktop/Angular2/src/app/app.component.ts:8:2
Argument of type '{ selector: string; template: any; styles: any[]; directives: typeof MyComponentComponent[]; }' is not assignable to parameter of type 'Component'.
Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.
は、このアプリのために私のコードです:
import { Component } from '@angular/core';
import { MyComponentComponent } from './my-component/my-component.component'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
directives: [MyComponentComponent],
})
export class AppComponent {
title = 'app works!';
}
私は、生成されたコンポーネントのコードには触れなかったが、念のため:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
constructor() {
}
ngOnInit() {
}
}
あなたはangular2を使用していますか? – micronyks
使用している角バージョンと一致するバージョンのCLIを使用していますか?コンポーネントレベルの 'ディレクティブ'は廃止され、削除されました(RC6、IIRC)。 – jonrsharpe
ドキュメントに示されているようにnpmコマンドを使用して両方を今日インストールしました。両方とも最新でなければならない、私はそれらが一致するかどうかわからない。 –