我正在努力将ng2-dragula绑定到AspNetCore SPA template。尝试了一切,但仍然得到:
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' }
])
]
};
答案 0 :(得分:0)
尝试在您的app模块(顶级模块)中导入DragulaModule
答案 1 :(得分:0)
我希望您使用的是模块基础结构(如下所示):
在这个应用程序中,有一些模块,如仪表板,拖拉机等。
在这种情况下,如果您想添加拖拽拖放(ng2-dragula),您需要做的是,在DragulaModule
中添加app.module.ts
import { DragulaModule } from '../../node_modules/ng2-dragula/ng2-dragula';
一旦你这样添加,如果你试图在[dragula]='"bag-something"'
(html文件)中使用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
的路径可能因项目结构而异。