2016-09-06 4 views
0

私はAngular 2.0.0-rc6とng2-dragulaを使用しています。私は単語の簡単なリストを作成し、その中にn 'ドロップをドラッグできるようにしたかったのです。角度2&ng2-dragula - コンポーネントにディレクティブを追加する

属性「ディレクティブ」をコンポーネントに追加しようとすると、「ディレクティブ」はコンポーネントメタデータ型の一部ではなく、ディレクティブをコンポーネントにバインドすることはできません。 コンポーネント宣言内に属性 "directive"を実装したチュートリアルがいくつか見つかりました。

どのようにDragulaディレクティブをコンポーネントにバインドできますか?

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

import {Dragula, DragulaService} from 'ng2-dragula/ng2-dragula'; 

@Component({ 
    selector: 'my-app', 
    // directives: [Dragula], 
    // viewProviders: [DragulaService], 
    templateUrl: "app/templates/app.component.html" 
}) 

答えて

0

あなたはNgModuleのような以内にそれを宣言する必要があります:それは私の作品

... 
import {Dragula, DragulaService} from 'ng2-dragula/ng2-dragula'; 

@NgModule({ 
    imports: [ BrowserModule ], 
    declarations: [ App, Dragula ], 
    providers: [ DragulaService ], 
    bootstrap: [ App ] 
}) 
export class AppModule {} 

Plunker Example

+0

はあなたに感謝します。 Stefan、あなたのコードとは違う、app.module.tsのインポートだけです:import {Dragula、DragulaService}から 'ng2-dragula/ng2-dragula'; – NoP

関連する問題