1

我一直在尝试在我的 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>

我尝试从“ng2-dragula”、“ng2-dragula/ng2-dragula”和其他一些我在网上找到的解决方案中导入它们,但到目前为止还没有运气。当我尝试 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
4

1 回答 1

0
import {DragulaModule} from "ng2-dragula";

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

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

于 2020-01-21T08:11:45.213 回答