2

我正在努力将ng2-dragula绑定到AspNetCore SPA 模板。尝试了一切,但仍然得到:

Exception: Call to Node module failed with error: Error: Template parse errors:
Can't bind to 'dragula' since it isn't a known property of 'div'. ("
<div>
<div class='wrapper'>
<div class='container' [ERROR ->][dragula]='"first-bag"'>
<div>Drag/drop item 1</div>
</div>
"): ng:///AppModule/DragulaComponent.html@7:31
at syntaxError (C:\Users\...\ClientApp\dist\vendor.js:36125:34)
at ...

有人在 AspDotnetCoreSpa 中使用过 ng2-dragula 吗?

dragula.component.html

<div>
 <div class='wrapper'>
  <div class='container' [dragula]='"first-bag"'>
   <div>Drag/drop item 1</div>
  </div>
 </div>
</div>

dragula.component.ts

import { Component } from '@angular/core';
import { DragulaModule, DragulaService } from 'ng2-dragula'

@Component({
   selector: 'dragula',
   templateUrl: './dragula.component.html',
   styleUrls: ['../../../../node_modules/dragula/dist/dragula.min.css']
 })
 export class DragulaComponent {
}

app.module.client.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { DragulaModule } from 'ng2-dragula';
import { HttpModule } from '@angular/http';
import { sharedConfig } from './app.module.shared';

@NgModule({
    bootstrap: sharedConfig.bootstrap,
    declarations: sharedConfig.declarations,
    imports: [
        BrowserModule,
        FormsModule,
        DragulaModule,
        HttpModule,
        ...sharedConfig.imports
    ],
    providers: [
        { provide: 'ORIGIN_URL', useValue: location.origin }
    ]
})
export class AppModule {
}

app.module.shared.ts

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component'
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';
import { DragulaComponent } from './components/dragula/dragula.component';

export const sharedConfig: NgModule = {
    bootstrap: [ AppComponent ],
    declarations: [
        AppComponent,
        NavMenuComponent,
        CounterComponent,
        FetchDataComponent,
        DragulaComponent,
        HomeComponent
    ],
    imports: [
        RouterModule.forRoot([
            { path: '', redirectTo: 'home', pathMatch: 'full' },
            { path: 'home', component: HomeComponent },
            { path: 'counter', component: CounterComponent },
            { path: 'fetch-data', component: FetchDataComponent },
            { path: 'dragula', component: DragulaComponent },
            { path: '**', redirectTo: 'home' }
        ])
    ]
};
4

2 回答 2

1

尝试DragulaModule在您的应用程序模块中导入(顶级模块)

于 2017-06-05T03:55:19.733 回答
0

我希望您使用的是模块基础结构(如下所示):

点击:项目结构

在这个应用程序中,有仪表板、dragula..等模块。

在这种情况下,如果你想添加dragula拖放(ng2-dragula),你需要做的是,DragulaModuleapp.module.ts使用 中添加import { DragulaModule } from '../../node_modules/ng2-dragula/ng2-dragula';

一旦你像这样添加,如果你尝试在 html 文件中使用[dragula]='"bag-something"'dragula.component.html它仍然会给出错误Can't bind to 'dragula' since it isn't a known property of 'div'.

所以解决方案是添加DragulaModule到模块的文件中。xxx.module.ts在这种情况下,您必须添加到 Dragula 模块的dragula.module.ts文件中。

注意:导入时DragulaModule的路径ng2-dragula/ng2-dragula可能因您的项目结构而异。

于 2017-07-05T06:11:25.460 回答