Angular 2不能与' dragula'因为它不是'

时间:2017-06-19 11:46:59

标签: javascript angular npm webpack ng2-dragula

我一直试图在我的Angular 2应用程序中使用dragula,但我无法使其工作。

以下是我在app.module.ts中的内容

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

@NgModule({
    imports: [
        // ...
        DragulaModule
    ],
    declarations: [ ... ],
    providers: [
        DragulaService
    ],
    bootstrap: [ ... ]
})
export class AppModule {}

在我使用Dragula的组件中,我以这种方式导入它:

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

export class MyComponent implements OnInit, OnDestroy {

    constructor(private dragulaService: DragulaService) {}

这是我试图在视图中构建的简单事情,它不起作用:

<ul [dragula]="'one'" [dragulaModel]="items">
    <li *ngFor="let item of items">{{item}}</li>
</ul>

我尝试从&#39; ng2-dragula&#39; ng2-dragula / ng2-dragula&#39;中导入它们。以及其他一些我在网上找到的解决方案,但到目前为止还没有运气。当我尝试使用console.log DragulaModule和DragulaService查看是否找到它们时,DragularService返回一个包含内容的函数,而DragulaModule返回一个空函数。

以下是我在控制台中遇到的错误:

Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'dragula' since it isn't a known property of 'ul'. ("span> </div> </header> <div class="alert-container"> <jhi-alert-error></jhi-alert-error> </div> <ul [ERROR ->][dragula]="'one'" [dragulaModel]="items"> <li *ngFor="let item of items">{{item}}</li> </ul> <div cla"): MatrixDetailComponent@0:943
Can't bind to 'dragulaModel' since it isn't a known property of 'ul'. ("der> <div class="alert-container"> <jhi-alert-error></jhi-alert-error> </div> <ul [dragula]="'one'" [ERROR ->][dragulaModel]="items"> <li *ngFor="let item of items">{{item}}</li> </ul> <div class="container-flui"): MatrixDetailComponent@0:961
Error: Template parse errors:
Can't bind to 'dragula' since it isn't a known property of 'ul'. ("span> </div> </header> <div class="alert-container"> <jhi-alert-error></jhi-alert-error> </div> <ul [ERROR ->][dragula]="'one'" [dragulaModel]="items"> <li *ngFor="let item of items">{{item}}</li> </ul> <div cla"): MatrixDetailComponent@0:943
Can't bind to 'dragulaModel' since it isn't a known property of 'ul'. ("der> <div class="alert-container"> <jhi-alert-error></jhi-alert-error> </div> <ul [dragula]="'one'" [ERROR ->][dragulaModel]="items"> <li *ngFor="let item of items">{{item}}</li> </ul> <div class="container-flui"): MatrixDetailComponent@0:961

1 个答案:

答案 0 :(得分:0)

import {DragulaModule} from "ng2-dragula";

@NgModule({
imports: [DragulaModule],
declarations: []
});

此修复程序将起作用...