2016-11-10 13 views
5

初心者は角度2で、私は最後の角度2のリリースバージョンを使用しています。私はそれに奇妙な問題があります。 これは私のdatabinding.component.tsコードです:角度2のエラー( '指令'は 'コンポーネント'タイプには存在しません)

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

import {PropertyBindingComponent} from './property-binding.component'; 
import {EventBindingComponent} from './event-binding.component'; 


@Component({ 
    selector: 'fa-databinding', 
    templateUrl: 'databinding.component.html', 
    styleUrls: ['databinding.component.css'], 
    directives: [PropertyBindingComponent, EventBindingComponent] 
}) 

、これが私のapp.module.tsコードの平和です:

import { PropertyBindingComponent } from './databinding/property-binding.component'; 
import { EventBindingComponent } from './databinding/event-binding.component'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    OtherComponent, 
    AnotherComponent, 
    DatabindingComponent, 
    PropertyBindingComponent, 
    EventBindingComponent 
    ] 

このコードは正しく動作しません。

ERROR in [default] /home/tornado/work/first-app/src/app/databinding/databinding.component.ts:11:2 
Argument of type '{ selector: string; template: any; styles: any[]; directives: (typeof PropertyBindingComponent | ...' is not assignable to parameter of type 'Component'. 
    Object literal may only specify known properties, and 'directives' does not exist in type 'Component'. 

どうすればいいですか!

+0

[Angular2バージョンRC.6のディレクティブ]が@Component Errorの内部にあります(http://stackoverflow.com/questions/39410591/angular2-version-rc-6-directives-inside-component-error) – Fiddles

答えて

12

directivesをコンポーネントから削除しました。 以下を参照してください。https://stackoverflow.com/a/39410642/5487673

問題を解決するには、コンポーネントからdirectives属性を削除するだけです。あなたのdirectives属性の下にリストされたコンポーネントがNgModuleレベルで宣言されている限り、あなたは正しいはずです。

+1

ありがとう、Simon :-) –

+1

この回答が参考になった場合は、✓チェックボタンをクリックしてください。 –

+0

私は '束縛'のために同じものを持っています、おそらく私たちを空手のままにする代わりに代わりを提供します。 – tatsu

0

私はそのケースに遭遇し、解決しました。 ディレクティブとして、特定のコンポーネントにインポートしプラグする必要はありません。 このように使用できます。

まず、app.module.tsにインポートします。 2番目に、インポートされたディレクティブを宣言に追加します。 それから彼らは働くでしょう。

関連する問題